Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dylanjhunt/0ef6dcce9a809c1836e8e545aa16f20e to your computer and use it in GitHub Desktop.
Save dylanjhunt/0ef6dcce9a809c1836e8e545aa16f20e to your computer and use it in GitHub Desktop.
Show all colors for a product as separate products on collection page
{% for product in collection.products %}
{% assign color_active = false %}
{% for option in product.options %}
{% if option == 'Color' %}
{% assign color_active = true %}
{% endif %}
{% endfor %}
{% if product.variants.size > 1 and color_active == true %}
{% for option in product.options %}
{% if option == 'Color' %}
{% assign index = forloop.index0 %}
{% assign colorlist = '' %}
{% assign color = '' %}
{% for variant in product.variants %}
{% capture color %}
{{ variant.options[index] }}
{% endcapture %}
{% unless colorlist contains color %}
<-- INSERT VARIANT LOOP -->
{% capture tempList %}
{{colorlist | append: color | append: " " }}
{% endcapture %}
{% assign colorlist = tempList %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
{% else %}
<-- INSERT PRODUCT LOOP -->
{% endif %}
{% endfor %}
@Electro2903
Copy link

Hi, this works perfectly! But can I make it automatically choose the variant you clicked on?
Because when I click a specific colour of the product on the collection page, it just goes to the default product, where you have to choose the variant. I would like to make it select the variant you chose automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment