Add multiple products to cart

PHOTO EMBED

Thu Nov 04 2021 11:56:21 GMT+0000 (UTC)

Saved by @JureVidmar #javascript

<form action="/cart/add" method="post" enctype="multipart/form-data" id="formAddToCart">
    <div class="product-quantity-wrapper">
      <button class="product-minus-btn product__qty-btn" type="button" name="button">
        <i class="fa fa-minus"></i>
  </button>
  <input type="number" id="Quantity-product-template" name="quantity" value="1" min="1" pattern="[0-9]*" class="product-form__input product-form__input--quantity" data-quantity-input="">
    <button class="product-plus-btn product__qty-btn" type="button" name="button">
      <i class="fa fa-plus"></i>
  </button>
  </div>c
  <input class="variant variant_selected" type="hidden" name="id" value="37390541553813">
    <button type="submit" name="add" aria-label="Add to cart" class="btn new-ajax-btn product-form__cart-submit" aria-haspopup="dialog" data-add-to-cart="">
      <span data-add-to-cart-text="">

        Add to cart

          </span>
  <span class="hide" data-loader="">
    <svg aria-hidden="true" focusable="false" role="presentation" class="icon icon-spinner" viewBox="0 0 20 20"><path d="M7.229 1.173a9.25 9.25 0 1 0 11.655 11.412 1.25 1.25 0 1 0-2.4-.698 6.75 6.75 0 1 1-8.506-8.329 1.25 1.25 0 1 0-.75-2.385z" fill="#919EAB"></path></svg>
      </span>
  </button>
</form>


$('.product__qty-btn').click(function(){
    var qtyInput = $('#Quantity-product-template').val()
    if ($(this).hasClass('product-plus-btn')) {
        var qtyNew = parseInt(qtyInput) +1 
        $('#Quantity-product-template').val(qtyNew)
    }
    if ($(this).hasClass('product-minus-btn')) {
        if (qtyInput <= 1) {
            var qtyNew = qtyInput
        }
        else {
            var qtyNew = qtyInput-1
        }
        $('#Quantity-product-template').val(qtyNew)
    }
})


<!-- OR BOTTOM ONE-->



$('.bogo__atc').click(function(){
  	$(this).text('Checking out ...');
    var prod1 = $('.ups_inp1').val();
    console.log('prod 1: '+ prod1)
    var prod2 = $('.ups_inp2').val();
    console.log('prod 2: '+ prod2)
    var prod3 = $('.ups_inp3').val();
    console.log('prod 3: '+ prod3)
    var prod4 = $('.ups_inp4').val();
    console.log('prod 4: '+ prod4);
    ajaxMultiBuy=function(o){
      var a=o.shift();
      console.log("Adding "+a+"..."),$.ajax({
        type:"POST",
        url:"/cart/add/?id="+a,
        dataType:"HTML",
        success:function(){
          console.log("Done."),
            0==o.length?(console.log("Loading cart..."),
                         window.location.replace("/checkout")):ajaxMultiBuy(o)},
        error:function(o){
        }
      })
    },
    productIDs=[prod1,prod2,prod3,prod4],ajaxMultiBuy(productIDs);
  });
content_copyCOPY

SleepWell

https://sleep-well-tech.myshopify.com/admin/themes/127408996561?key