Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bjornbennett/47711d18768fc0dfcf42c7a5174578ea to your computer and use it in GitHub Desktop.
Save bjornbennett/47711d18768fc0dfcf42c7a5174578ea to your computer and use it in GitHub Desktop.
Shopify Liquid - With this Liquid snippet, you are able to grab variants of a product, assign it to an option within a Select HTML element. This also grabs the product sku number, variant value, title, and variant URL. Currently set to 3, but can be extended for however many you need.
{% comment %}Assign products set in Settings to variables{% endcomment %}
{% assign productOne = all_products[settings.product_one] %}
{% assign productTwo = all_products[settings.product_two] %}
{% assign productThree = all_products[settings.product_three] %}
<!--Output variant info to option elements within a Select HTML element-->
<select>
{%for variant in productOne.variants%}
<option sku="{{variant.sku}}" value="{{variant.url | split: '?variant=' | last}}">1 - {{variant.title}} - {{productOne.url}}</option>
{%endfor%}
{%for variant in productTwo.variants%}
<option sku="{{variant.sku}}" value="{{variant.url | split: '?variant=' | last}}">2 - {{variant.title}} - {{productTwo.url}}</option>
{%endfor%}
{%for variant in productThree.variants%}
<option sku="{{variant.sku}}" value="{{variant.url | split: '?variant=' | last}}">3 - {{variant.title}} - {{productThree.url}}</option>
{%endfor%}
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment