Add to cart in Shopify using Ajax Jquery,add to cart with ajax in shopify,add to cart using ajax in shopify,add item to cart using ajax in shopify,how to add product in cart using ajax in shopify,ajax add to cart in shopify,add product using ajax in shopify,shopify add to cart using ajax,add to cart with ajax in shopify,add to cart using ajax in shopify,add item to cart using ajax in shopify,how to add product in cart using ajax in shopify,ajax add to cart in shopify,add product using ajax in shopify,shopify ajax add to cart example,shopify add product to cart ajax

Add to cart in Shopify using Ajax Jquery

Add to cart in Shopify using Ajax Jquery

Hi in this tutorial we will integrate add to cart in Shopify using Ajax:-

Step 1:- First you need to change the add t cart button to below. Also, you need to add a unique id or class to the Add to cart form like below:-

Step 3:- Add Spinner to button using below CSS code:-

.btnloading{
      position: relative;
    }
    .btnloading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    border: 4px solid transparent;
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: button-loading-spinner 1s ease infinite;
}
    @keyframes button-loading-spinner {
  from {
    transform: rotate(0turn);
  }

  to {
    transform: rotate(1turn);
  }
}

Step 3: hit the add to cart API

    function addItem(form_id,btnclass){
      var cls = '.'+btnclass;
      console.log(cls);
      $(cls).addClass('btnloading');
      $.ajax({
        type: 'POST', 
        url: '/cart/add.js',
        dataType: 'json', 
        data: $('#'+form_id).serialize(),
        async:false,
        success: function(result){
          var cart_count = $(".maincart span:first-child").text();
          
          cart_count++;
          
          $(cls).removeClass('btnloading');
          $('.maincart').removeClass('hide');
          $('.maincart2').removeClass('hide');
          
          console.log(cart_count);

            
          $(".maincart span:first-child").text(cart_count);
          
          $(".maincart2 span:first-child").text(cart_count);
          
          },
        error:function(result){
          $(cls).removeClass('btnloading');
        }
      });
    }

Add to cart in Shopify using Ajax Jquery,add to cart with ajax in shopify,add to cart using ajax in shopify,add item to cart using ajax in shopify,how to add product in cart using ajax in shopify,ajax add to cart in shopify,add product using ajax in shopify,shopify add to cart using ajax,add to cart with ajax in shopify,add to cart using ajax in shopify,add item to cart using ajax in shopify,how to add product in cart using ajax in shopify,ajax add to cart in shopify,add product using ajax in shopify,shopify ajax add to cart example,shopify add product to cart ajax

Post Created 120

Leave a Reply

Related Posts

Begin typing your search above and press enter to search. Press ESC to cancel.

Back To Top