Multiple Variant drop down to buy multiple variant onclick single cart button
Demo url: https://www.snowfeetstore.com/products/2-pairs
<div class="swtch-mrgn">
<a class="tab-prod-btn" href="/products/2-pairs">2 Pairs</a>
<a class="tab-prod-btn" href="/products/3-pairs">3 Pairs</a>
<a class="tab-prod-btn" href="/products/4-pairs">4 Pairs</a>
<a class="tab-prod-btn" href="/products/5-pairs">5 Pairs</a>
<a class="tab-prod-btn selected" href="/products/10-pairs">10 Pairs</a>
</div>
/* form code */
{% capture form_id %}AddToCartForm-{{ section_id }}{% endcapture %}
<form action="/cart/add" method="post" class="variants cart" id="product-actions-{{ product.id }}" enctype="multipart/form-data">
<select name="id[]" id="productSelect_left" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_right" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_three" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_four" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_five" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_six" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_seven" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_eight" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_nine" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<select name="id[]" id="productSelect_ten" class="product-form__variants no-js bundle_slt_border">
{% for variant in product.variants %}
<option value="{{ variant.id }}" data-price="{{ variant.price }}" data-com-price="{% if variant.compare_at_price >= variant.price %} {{variant.compare_at_price}} {% else %}{{variant.price}} {% endif %}">
{{ variant.title }}
</option>
{% endfor %}
</select>
{% if quantity_enable %}
<div class="product__quantity product__quantity--{{ variant_type }}">
<label for="Quantity-{{ section_id }}" class="variant__label">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity-{{ section_id }}" name="quantity" value="1" min="1">
</div>
{% endif %}
{%- assign enable_dynamic_buttons = false -%}
{% if enable_payment_button and template != 'product.preorder' %}
{%- assign enable_dynamic_buttons = true -%}
{% endif %}
{% if enable_dynamic_buttons %}
<div class="payment-buttons">
{% endif %}
<button
{% if product.empty? %}type="button"{% else %}type="submit"{% endif %}
name="add"
data-add-to-cart
class="{% if enable_dynamic_buttons %}btn btn--tertiary{% else %}btn{% endif %} btn--full add-to-cart"
{% unless current_variant.available %} disabled="disabled"{% endunless %}>
<span data-add-to-cart-text>
{% if current_variant.available %}
{% if template == 'product.preorder' %}
{{ 'products.product.preorder' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endif %}
{% else %}
{{ 'products.product.sold_out' | t }}
{% endif %}
</span>
</button>
{% if enable_dynamic_buttons %}
</div>
{% endif %}
{% unless product.empty? %}
<textarea class="hide" aria-hidden="true" data-variant-json>
{{ product.variants | json }}
</textarea>
{% if product.options.size > 1 %}
<textarea class="hide" aria-hidden="true" data-current-variant-json>
{{ current_variant | json }}
</textarea>
{% endif %}
{% endunless %}
<!-- <button style="margin-top:2em;" class="button buynow-btn" title="Buy" onClick="instantBuy()"><span>
</form>
<script src="https://ajax.googleapis.
<script>
function instantBuy(){
var $ = jQuery;
var formParams = $('form.cart').serialize();
$.ajax({
url: "/cart/add",
type: "post",
data: formParams,
success: function(){
window.location.href = "/checkout";
},
error: function(){
}
})
}
// $(document).ready(function(){
// calculatePrice()
// function calculatePrice(){
// var option,price=0;
// $('.bundle_slt_border').each(
// option = $(this).find('option:selected'
// console.log(option[0].dataset.
// price += parseFloat(option[0].dataset.
// });
// console.log(price,'price');
// $('.product__price').html(
// console.log(theme.Currency.
// }
// $('.bundle_slt_border').on('
// calculatePrice();
// });
// })
$(document).ready(function(){
calculatePrice()
function calculatePrice(){
var option,price=0,com_price=0;
$('.bundle_slt_border').each(
option = $(this).find('option:selected'
price += parseFloat(option[0].dataset.
console.log(option[0].dataset.
com_price += parseFloat(option[0].dataset.
});
$('.product__price').html(
$('.product__price--compare').
}
$('.bundle_slt_border').on('
calculatePrice();
});
})
</script>
comment
Posted by Patrick's Bellevue on
Awesome work perfect!!!!!
Thank for the code