Finding specific product tag in Javascript?

MadisonJMerchel
New Member
1 0 0

Hi all, 

I am working on this line of JS in my theme (Impulse), and am a bit stuck on how to properly write it:

 

delayMessage: product.product_tags.includes('Tees'),


Essentially I am looking to define 'delayMessage' by the product tag 'Tees', however I cannot figure out how to find that specific tag in Javascript using the product object.

I've tried the following as well, however can't seem to get it to work:

 

delayMessage: product_tags == 'Tees',
delayMessage: product.product_tags == "Tees",
delayMessage: product.tags.includes('Tees'),


What would be the correct way to write this? As products normally have multiple tags, do you need to loop through them similar to liquid?

0 Likes
Jason
Shopify Expert
10037 119 1873

So it looks like you've got a product object created, but what are the contents of that?
I don't have the theme handy but that's a good place to start.

Depending on how that object is constructed I'd expect the tags to either be an array, or a just a string of comma separated values. Knowing the data structure helps us move on too many more assumptions.

If there's a public link that makes this clearer for the forum members without having to dive into a giant explanation, then share that instead.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes