Simple Product detail page “Add to Cart” not adding to cart
-
Mostly writing to report a flaw in the way simple product detail pages are submitting their Add to Cart form.
In the latest version of Woocommerce, Simple Product detail pages submit their
add-to-cart
product id value through a <button> element. Unfortunately this doesn’t work consistently and should likely be rewritten as using a hidden <input> element with name=”add-to-cart”. This was how we solved the issue.Unfortunately we’ll have to continuously apply this fix whenever Woocommerce plugin gets updated, but here’s what we do to fix:
Open
/plugins/woocommerce/templates/single-product/add-to-cart/simple.php
Add:
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->get_id() ); ?>">
Comment out the <button> submit and replace it with an input submit:
<input type="submit" value="<?php echo esc_html( $product->single_add_to_cart_text() ); ?>" class="single_add_to_cart_button button alt">
Hopefully Woocommerce can apply this fix for future updates. Using a <button> submit with values attached doesn’t work as expected.
- The topic ‘Simple Product detail page “Add to Cart” not adding to cart’ is closed to new replies.