Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zakhardage/6096473 to your computer and use it in GitHub Desktop.
Save zakhardage/6096473 to your computer and use it in GitHub Desktop.
Auto-selecting the first available variant so that your product does not look sold out
<select id="product-select" name="id">
{% assign selected = 'notYet' %}
{% for variant in product.variants %}
{% if variant.available and selected == 'notYet' %}
<option value="{{ variant.id }}" selected="selected">{{ variant.title }}</option>
{% assign selected = 'alreadySelected' %}
{% else %}
<option value="{{ variant.id }}">{{ variant.title }}</option>
{% endif %}
{% endfor %}
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment