Skip to content

Instantly share code, notes, and snippets.

@kyleaparker
kyleaparker / gist:9691004
Created March 21, 2014 17:12
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 %}
@kyleaparker
kyleaparker / gist:9665660
Created March 20, 2014 14:57
Shopify: Show number of variants still available
{% assign total = product.variants | map: 'available' | join: ", " | remove: 'false, ' %}
{% assign available = total | split: ',' %}
{{ available.size }} of {{ product.variants.size }} left
@kyleaparker
kyleaparker / gist:9665395
Created March 20, 2014 14:45
Shopify: Remove sold out options from variant drop down
{% if product.options.size == 1 %}
{% for variant in product.variants %}
{% unless variant.available %}
jQuery('.single-option-selector option:contains(' + {{ variant.title | json }} +')').remove();
{% endunless %}
{% endfor %}
jQuery('.single-option-selector').trigger('change');
{% endif %}