Count products in cart that have a specific option value selected

Highlighted
New Member
2 0 0

Hello,

 

Basically, I am trying to count only the number of items in my cart that have a certain option value selected/added to their cart. Below is my attempt at this implementation:

 

  {%- assign count = 0 -%}

    {%- for item in cart.items.product_options.values -%}
    	{%- if item == "Green" -%}
    		{%- assign count = count | plus: 1 -%}
    	{%- endif -%}
    {%- endfor -%}

{{ count }}

I've added several items with the specific option value selected (green, in this case). The above code doesn't work properly as my {{ count }} result shows 0. Any help on this? Thanks.

0 Likes