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

July 5th, 2017 Wordpress 663 views

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 :

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

Hope you find it useful.

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

Leave your comments: