Counting the number of colors for an item on a collection page

New Member
1 0 0

I'm trying to add a count of the number of available colors for an item on the listing on the collection page.  I have looked at many different articles and threads to build my code. Based on the articles I've read my code should work, but it only outputs the total count of all variants (size/color) plus 1. Here's my code:

 

 
{% assign value = 0 %}
  
  {% if product.available %}
    {% for product_option in product.options_with_values %}
{% if product_option.name == 'Sizes' or product_option.name == 'sizes' or product_option.name == 'size' or product_option.name == 'Size' %}
        {% for value in product_option.values %}
        	{% assign value = value | plus: 1 %}
        {% endfor %}
           {% endif %}
    {% endfor %}
  {% endif %}
  
  {% if value > 0 %}<small>Colors available - {{ value }}</small>{% endif %}
 
0 Likes