Skip to content

Instantly share code, notes, and snippets.

@kyleaparker
Created March 21, 2014 17:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyleaparker/9691004 to your computer and use it in GitHub Desktop.
Save kyleaparker/9691004 to your computer and use it in GitHub Desktop.
Shopify: Show number of colors available
{% for option in product.options %}
{% if option contains "Color" %}
{% assign optionName = "option" | append: forloop.index %}
{% assign colors = product.variants | map: optionName %}
{% assign colorsFiltered = '' %}
{% for colorOption in colors %}
{% unless colorsFiltered contains colorOption %}
{% assign colorsFiltered = colorsFiltered | append: ', ' | append: colorOption %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
{% assign uniqueColors = colorsFiltered | remove_first: ', ' | split: ', ' %}
{% if product.options contains "Color" %}{{ uniqueColors.size }} colors available{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment