Last active
March 11, 2022 16:59
-
-
Save dylanjhunt/0ef6dcce9a809c1836e8e545aa16f20e to your computer and use it in GitHub Desktop.
Show all colors for a product as separate products on collection page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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 %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.