Web Development. Client Satisfaction. Web Consultancy. Professional. UX. Fast. Responsive Design. Dynamic. Interactive. Innovative. Ecommerce. Wordpress plugins. Prestashop modules. You name it.

Add to cart via AJAX Woocommerce without loop

Add to cart via AJAX Woocommerce without loop

To accomplish this functionality you have to make a GET call by javascript, in this call you have to pass the ID of product.

Below you can see an example for this action.


<div class="add_to_cart"> 
<a href="#" data_id="12">Add to cart</a> 


Where data_id is the product id.



jQuery('.add_to_cart').on('click', function(e){

var href = window.location.href;

var product_id = jQuery(this).attr('data_id');

jQuery.get(href+'?add-to-cart='+product_id, function(){

console.log('cart updated');




Leave a Reply

Notify of