Last active
June 21, 2021 20:45
-
-
Save carolineschnapp/6082654 to your computer and use it in GitHub Desktop.
Script that checks if a product has a Colo(u)r option and is available in more than 1 color.
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
{% assign has_color = false %} | |
{% assign option_index = 0 %} | |
{% for option in product.options %} | |
{% capture downcased_option %}{{ option | downcase }}{% endcapture %} | |
{% if downcased_option contains 'color' or downcased_option contains 'colour' %} | |
{% assign option_index = forloop.index0 %} | |
{% assign has_color = true %} | |
{% endif %} | |
{% endfor %} | |
{% if has_color %} | |
{% assign how_many_colors = 0 %} | |
{% assign colors = '' %} | |
{% for variant in product.variants %} | |
{% assign color = variant.options[option_index] | append: ',' %} | |
{% unless colors contains color %} | |
{% assign colors = colors | append: color %} | |
{% assign how_many_colors = how_many_colors | plus: 1 %} | |
{% endunless %} | |
{% endfor %} | |
{% if how_many_colors > 1 %} | |
<p>Available in more colors</p> | |
{% endif %} | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment