When a snippet is rendered, how do we get the code in the snippet to work?

Solved

When a snippet is rendered, how do we get the code in the snippet to work?

KlaudiaZapiet
Shopify Partner
68 4 10

Hi Shopify fam!

 

Looking for some help here 🙂

I'm trying to code a simple condition for product tags. If the product tag is in the cart, do something.

 

I added the code in the cart-item snippet file on lines 112-114:

Screenshot 2023-02-01 at 2.07.29 PM.png

 

 

However, I realized that when the snippet is rendered, my code is not executing. Cart-item is being rendered into the main-cart file:

 

Screenshot 2023-02-01 at 2.07.56 PM.png

 

 

What should I add or change so that the condition works when rendered? Thanks in advance!

Klaudia from Zapiet
Learn more about our apps at Zapiet
Accepted Solution (1)
KlaudiaZapiet
Shopify Partner
68 4 10

This is an accepted solution.

@SomeUsernameHe Thanks for your help, unfortunately, it didn't work either.

Klaudia from Zapiet
Learn more about our apps at Zapiet

View solution in original post

Replies 4 (4)

SomeUsernameHe
Shopify Partner
519 58 113

Capitalization matters with tags. Can I see the tag you add to the product?

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee
KlaudiaZapiet
Shopify Partner
68 4 10

@SomeUsernameHe , sure, the tag's text was copied and pasted so it can't be wrong. 

Screenshot 2023-02-01 at 2.43.52 PM.png

 

I believe the issue is related to how the snippet renders. When I copy all of the code from the cart-item snippet and paste it where it's supposed to render, then it works. But I would like to know how to make it work through the render. 

Klaudia from Zapiet
Learn more about our apps at Zapiet
SomeUsernameHe
Shopify Partner
519 58 113

Try inserting 

{% for item in cart.items %}

before   

 

 

{% if item.product.tags ... %}

 

 

 

and then insert 

 

 

{% endfor %}

 

 

after the 

 

 

{% endif %}

 

 

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee
KlaudiaZapiet
Shopify Partner
68 4 10

This is an accepted solution.

@SomeUsernameHe Thanks for your help, unfortunately, it didn't work either.

Klaudia from Zapiet
Learn more about our apps at Zapiet