How to add text into the descrition only if Tag is present in Product Tags

Luke_ODea
New Member
11 0 0

Hello guys, Im trying to display a piece of text in my item description only if i have a certain tag in the product tags for each item.

 

Im trying to display:

Made to order: (delivery may take an extra 7 days)

note: i would like to be able to change this text without having to change every tag, instead only chanding the text in the piece of code.

 

the tag i will be using in product tags will be: 'madetoorder'

 

Am I aiming in the right direction using the code below?

{% for tag in product.tags %}
  {% if tag contains 'madetoorder' %}
     {{Made to order: (delivery may take an extra 7 days)}}
  {% endif %}
{% endfor %} 

 

my store is: ultralighting.com.au

 

THANKYOU :)

0 Likes
tim
Shopify Expert
2926 143 1021

Hi Luke, 

almost there, your code should work (if you remove {{}} around the message), but the loop is unnecessary: 

  {% if product.tags contains 'madetoorder' %}
     Made to order: (delivery may take an extra 7 days)
  {% endif %}

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
Luke_ODea
New Member
11 0 0

Thanks Tim :) 

For some reason, when i paste that code in, it doesnt display, but if i type TEST in the same spot where id place the code, TEST will display.

Cheers

0 Likes
tim
Shopify Expert
2926 143 1021

Well, are you sure the product has the tag, and the tag is exactly like it is written here?

I rechecked the code just now in my test shop and it works fine.

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes
Luke_ODea
New Member
11 0 0

Thanks for your help Tim, its now fixed because of your advice.

Really appreciate your help once again :) 

Cheers :)

0 Likes
Jason
Shopify Expert
10360 158 2005

This code isn't structured correctly:

{% for tag in product.tags %}
{% if product.tags contains 'madetoorder' %}
Made to order: (delivery may take an extra 7 days)
{% endif %}
{% endfor %} 

It should be more like this:

{% for tag in product.tags %}
{% if tag contains 'madetoorder' %}
  Made to order: (delivery may take an extra 7 days)
{% endif %}
{% endfor %} 

or

{% for tag in product.tags %}
{% if tag == 'madetoorder' %}
  Made to order: (delivery may take an extra 7 days)
{% endif %}
{% endfor %} 

Now if this isn't working...

{% if product.tags contains 'madetoorder' %}
Made to order: (delivery may take an extra 7 days)
{% endif %}

... it would suggest that you either:

  • don't have a product object, or
  • the product doesn't have tags, or
  • you don't have that exact tag in the array of tags. 

That last code block above is saying "if one of the tags on this product equals madetoorder then do something". 

Can you share a link to the product that has the code in place? That may help identify any remaining issues you've got. If would also help to know exactly what they tags are that are outputted when you loop over them and use {{ tag }}.

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes
Luke_ODea
New Member
11 0 0

Thanks so much for the reply jason, I just solved the issue as you posted that, I just edited that previous post. Really appreciate your help on the topic also.  :)

0 Likes
Luke_ODea
New Member
11 0 0

One more thing, how do i get it to display a different piece of text if that tag is not tagged on a product?

0 Likes
tim
Shopify Expert
2926 143 1021

Easy, mate:

 {% if product.tags contains 'madetoorder' %}
     Made to order: (delivery may take an extra 7 days)
 {% else %}
     You will receive it in 24 hours!
 {% endif %}

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
Luke_ODea
New Member
11 0 0

Cheers Tim, I really appreciate your help once again :)

0 Likes