Personalized checkout and custom promotions with Shopify Scripts
I'm trying to find a way to solve an issue with adding or hiding items on a specific product using the product tag. I tried to use code for this:
{% for item in cart. items %}
{% if item.product.tags contains 'swatch' %}
// my text //
{% endif %}
{% endfor %}
But it didn't work for me, because this text was displayed in all products in the cart, even if other products did not have the "swatch" tag. Please help me solve this problem. Thanks!
I know this is an old question, but I'm commenting in case someone comes across this later and doesn't catch the issue.
There is a typo in '{% for item in cart. items %}', an extraneous space after cart.
The correct code should be:
{% for item in cart.items %}
{% if item.product.tags contains 'swatch' %}
// my text //
{% endif %}
{% endfor %}
Or if you want to show the text for everything BUT a tag:
{% for item in cart.items %}
{% unless item.product.tags contains 'swatch' %}
// my text //
{% endunless %}
{% endfor %}
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025