Ad

Shopify (Liquid) If Product Has A Tag, Echo That Tag

- 1 answer

I'm trying to find product tags that meet a condition, and then display those tag(s).

This gets me all the tags for a product...

{% for tag in product.tags %}
{% if product.tags contains '336699' %}
{{ tag }}
{% endif %}
{% endfor %}

How can I just echo the tags that meet the 'contains' criteria?

Ad

Answer

You're almost there. Use for to iterate the product.tags and contains within a if to match tag with your string literal criteria.

{% for tag in product.tags %}
    {% if tag contains '336699' %}
        {{ tag }}
    {% endif %}
{% endfor %}
Ad
source: stackoverflow.com
Ad