Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Hide or add items for a specific product in the cart page.

Hide or add items for a specific product in the cart page.

nikexen
Visitor
1 0 0

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!

Reply 1 (1)

jaydawgz
Visitor
2 0 3

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 %}