Question

I have a client site, https://www.ndsclub.com/product/bcaa-page/, where there are AJAX 'add to cart' buttons auto-generated by WooCommerce.

If I visit the page with an empty cart and click ADD it adds a single item to the cart as expected. The page is reloaded and a popup cart slides into the window.

If I refresh the browser a second item is added to the cart without clicking the ADD button.

How to prevent such bug?

  • This is not a query param problem, there url is clean
  • I had a second product on the same page, clicking ADD (p1) and then after the reload clicking ADD (p2), p1 gets added a second time so I have a total of 3 items in the cart after two clicks
Was it helpful?

Solution

If you look on the network tab of the developer tools from your browser, you will see that the product is NOT added by AJAX.

Chrome network tab

Yes, there is an AJAX-Request but that sends a nonce to "woosb_custom_data" and adds no product to your cart. (blue cross on the screenshot)

Normaly the "add to cart" AJAX-Request should go to an address like "example.com/?wc-ajax=add_to_cart".

The product is add via a normal POST-Request. (red cross on the screenshot)

If you reload the page the browser will send the POST-Request again. Try the reload test with an firefox browser and the browser will ask you if you want to send the POST-Request again.

By the way there is an problem with your cart page.

https://www.ndsclub.com/cart/

If you remove all item from the cart (hit the red cross for every item) the cart-view will be white and there is no navigation back to your shop.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top