Issue
I have one hidden dropdown and two variant-selector
dropdowns.
One dropdown is for color
and the second one is for size
.
I want to add size
data in data-size=""
and color
data in data-color=""
in the dropdown of name=id
.
<form method="post" action="/cart/add">
{% if product.variants.size > 1 %}
{% for option in product.options_with_values %}
<select class="variant-selector {{option.name}}" data-var="{{forloop.index}}">
{% if product.available %}
{% for values in option.values %}
<option value="{{values}}">{{values}}</option>
{% endfor %}
{% endif %}
</select>
{% endfor %}
<select name="id" style="display:none;" id="data{{forloop.index}}">
{% for variant in product.variants %}
{% if variant.available %}
<option data-size="" data-color="" value="{{ variant.id }}" >{{ variant.title }}</option>
{% endif %}
{% endfor %}
</select>
{% if variant.available%}
<input type="hidden" min="1" type="number" name="quantity" value="1" />
<input type="submit" value="{{ 'products.product.add_to_cart' | t }}" class="btn add-to-cart" />
{% else %}
<input type="submit" value="{{ 'products.product.sold_out' | t }}" class="btn add-to-cart" disabled="disabled">
{% endif %}
{% endif %}
</form>
Solution
As Dave B comment I don't need option.value
in the loop of product.variants
in Shopify. I simply add data-size="{{ variant.option1 }}"
and data-color="{{ variant.option2 }}"
<select name="id" style="display:none;" id="data{{forloop.index}}">
{% for variant in product.variants %}
{% if variant.available %}
<option data-size="{{ variant.option1 }}" data-color="{{ variant.option2 }}" value="{{ variant.id }}" >{{ variant.title }}</option>
{% endif %}
{% endfor %}
</select>
Answered By - Anupam Mistry Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.