0
votes

I have implemented an ajax add to cart button on my woocommerce shop

echo sprintf( '<button type="submit" data-product_id="%s" data-product_sku="%s" data-quantity="1" class="%s button product_type_simple">%s</button>', esc_attr( $product->id ), esc_attr( $product->get_sku() ), esc_attr( $link['class'] ), esc_html( $link['label'] ) );

The button is working just fine and after clicking, the product is added to the cart And im using "added_to_cart" java-script hook to display the mini-cart as s a popup to the user.

only now 2 problems occur

1st problem : if i click the button again , instead of adding the item to the current quantity the page is refreshed and im getting the woocommerce message "you already have this item in your cart"

2nd and more crucial when im navigating directly to the "cart" page i don't see the item in the cart , if i refresh the cart page again , the item magically appears ...

Any thoughts ?

1

1 Answers

1
votes

For problem 1, it sounds like you selected the "Sold Individually - Enable this to only allow one of this item to be bought in a single order" check.

This is a setting found on the individual product page > the inventory tab.