I've added an add to cart button to my collection pages in shopify. The button works, however when a different option (size) than the default one is selected it still adds the default size to the cart. This is my code
{% for product in collection.products %}
<form action="/cart/add" method="post" enctype="multipart/form-data">
{% unless product.has_only_default_variant %}
{% for option in product.options_with_values %}
<div class="selector-wrapper js">
<div class="col-size">
<p>Select your size</p>
<select
id="single-option-selector"
data-single-option-selector
data-index="option{{ option.position }}" size="6">
{% if option.name == 'Size' %}
{% for value in option.values %}
<option
value="{{ value | escape }}"
{% if option.selected_value == value %}selected="selected"{% endif %}>
{{ value }}
</button>
</option>
{%endfor%}
{% endif %}
</select>
</div>
</div>
{% endfor %}
{% endunless %}
<select name="id" class="no-js" data-product-select>
{% for variant in product.variants %}
<option
{% if variant == current_variant %}selected="selected"{% endif %}
{% unless variant.available %}disabled="disabled"{% endunless %}
value="{{ variant.id }}">
{{ variant.title }}
</option>
{% endfor %}
</select>
<input type="submit" value="Add to cart" class="btn" />
<input type="hidden" name="return_to" value="back" />
</form>
{% endfor %}
Anybody got any idea how to fix this so the right option is added to the cart?
name="id"
select when you change thesingle-option-selector
select? If you don't you need to write one since the important select is the one with thename="id"
and that is what it's submitted to the cart. – drip