Add AJAX based “Add to cart” button on Woocommerce Product Page

Woocommerce provides a really nice ajax feature when we add products to the cart. So the page does not reload and the cart counts gets updated immediately. But it is limited for Product Listing/Archive page only. On the single product page (product details page), it doesn’t use the ajax based add to cart button. So every time you click it, it reloads the page and adds the item to cart.

Good thing, there is a way to use the same ajax based button on single product page. We can do it by simply using woocommerce_single_product_summary hook. Below is a small code snippet.

Below code will simply remove the old Add to cart button on single product page :

remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 );

And below code will add the ajax based Add to cart button on single product page :

add_action( 'woocommerce_single_product_summary', 'woocommerce_template_loop_add_to_cart', 30 );

Hope you find it useful.

Share it with others and leave your comments if any queries.

Update: This solution will not work for variable products and also it does not show quantity textbox. If you are looking for ajax support on Variable product, please check this tutorial.