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 %}
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024