Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save joe-dempsey/6ef2e9e047e8e95fde0342b7667b8289 to your computer and use it in GitHub Desktop.
Save joe-dempsey/6ef2e9e047e8e95fde0342b7667b8289 to your computer and use it in GitHub Desktop.
Shopify add color swatches/dots to collection pages.
{% capture option_titles %}Color,color,Colour,colour{% endcapture %}
{% assign option_titles = option_titles | split:',' %}
{% for option in product.options %}
{% if option_titles contains option %}
{% capture option_index %}option{{ forloop.index }}{% endcapture %}
{% assign option_values = product.variants | map: option_index | uniq %}
{% if option_values.size != 1 %}
{% for opt in option_values %}
<div style="background-color:{{ opt | downcase }};" class="option_circles"></div>
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
<style>
.option_circles {
height: 25px;
width: 25px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
border:1px solid #ccc;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment