Call just colors and not sizes

Hello on my collection page want to display all the color variant only and not sizes but it´s calling all. I´m using wookie theme. This is the code I´m using:

{%- if collection.products.size > 0 -%}
{% 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 = ‘’ %}
{% assign color_scheme = ‘’ %}
{% for variant in product.variants %}
{% capture color %}
{{ variant.options[index] }}
{% endcapture %}

{% unless colorlist contains color %}

{%- include 'product-grid-item-variant' -%}
{% capture tempList %} {{colorlist | append: color | append: " " }} {% endcapture %} {% assign colorlist = tempList %} {% endunless %} {% endfor %} {% endif %} {% endfor %} {% else %}
{%- include 'product-grid-item' -%}
{% endif %} {%- endfor -%} {%- else -%}

It´s working great but when calling the products have the same color with all the size variants. Anyone has the same problem?

Hello @Asepul
Try this

{%- if collection.products.size > 0 -%}
{% for product in collection.products %}
{% assign color_active = false %}
{% assign size_active = false %}
{% for option in product.options %}
{% if option == ‘Color’ %}
{% assign color_active = true %}
{% endif %}
{% if option == ‘Size’ %}
{% assign size_active = true %}
{% endif %}
{% endfor %}
{% if product.variants.size > 1 and color_active == true and size_active == false %}
{% for option in product.options %}
{% if option == ‘Color’ %}
{% assign index = forloop.index0 %}
{% assign colorlist = ‘’ %}
{% assign color = ‘’ %}
{% assign color_scheme = ‘’ %}
{% for variant in product.variants %}
{% capture color %}
{{ variant.options[index] }}
{% endcapture %}
{% unless colorlist contains color %}

{%- include 'product-grid-item-variant' -%}
{% capture tempList %} {{colorlist | append: color | append: " " }} {% endcapture %} {% assign colorlist = tempList %} {% endunless %} {% endfor %} {% endif %} {% endfor %} {% else %}
{%- include 'product-grid-item' -%}
{% endif %} {% endfor %} {%- else -%}
1 Like

Thank you for your help, when I put the code in the variant loop stop working and just display the main product. That´s the issue that it´s been happening so far, any idea on another solution? TIA