add multiple product to cart with one button?

New Member
1 0 0

You can use <input type="hidden" name="items[{{ forloop.index0 }}][id]" value="{{ variant.option2 }}" /> in Liquid file for form build.

 

// Liquid

<form id="product-form__bundle-{{ product.id }}" class="product-form__bundle text-center">
{% for variant in product.variants %}
<input type="hidden" name="items[{{ forloop.index0 }}][id]" value="{{ variant.option2 }}" />
{% endfor %}
<button type="button" class="addtocart"></button>
</form>

 

// Your javascript

$('.product-form__bundle .addtocart').on('click', function(){
var form = $(this).parent('form');

console.log($(form).serialize());

$.ajax({
type: "POST",
url: "/cart/add.js",
data: $(form).serialize(),
success: () => {
},
error: function(xhr, status, error) {
console.log(xhr);
},
dataType: "json",
});
});

0 Likes
Highlighted
New Member
1 0 0

What step do I need to take to input those codes?

0 Likes