Changing confirmation email text using product tags

Port5
New Member
2 0 0

Hello,

We're trying to add tags to products that users will pre-order through our system, and that will change the text of confirmation emails based on those tags. For example, normally our emails will read, "Most products ship within 1-2 days"; however, for pre-ordered products, we want to say something along the lines of, "Your order is estimated to ship on Nov. 11."

We have tried using an if statement for this, but it doesn't appear to be working -- likely due to how these are nested. Could you help me correct the code below so that this will work?

Thanks in advance.

{% if requires_shipping %}
  {% for tag in product.tags %}
    {% if tag == 'TAG THAT IDENTIFIES LATER SHIPPING DATE' %}
      Your item will ship on [date].
    {% else %}
      Your items will ship within 1-2 days.
    {% endif %}
  {% endfor%}
{% else %}
  Please email us with any further questions.
{% endif %}

 

0 Likes
Geoff
Shopify Staff (Retired)
Shopify Staff (Retired)
25 0 2

Hey Port5!

My name is Geoff - I'm a Guru here at Shopify.

I think you first need to call the line item product object before you can interact with the tags associated with it in your email templates. Take a look at the updated code below:

{% if requires_shipping %}
{% for line in line_items %}  
{% for tag in product.tags %}
    {% if tag == 'TAG THAT IDENTIFIES LATER SHIPPING DATE' %}
      Your item will ship on [date].
    {% else %}
      Your items will ship within 1-2 days.
    {% endif %}
  {% endfor%}
  {% endfor%}
{% else %}
  Please email us with any further questions.
{% endif %}

Give that a try and feel free to contact me back if you are still running into issues.

Happy selling!
-Geoff

0 Likes
Port5
New Member
2 0 0

Hi Geoff,

Thanks for the reply! I'm still having trouble with this, for whatever reason -- when I enter it into the Order Confirmation email template in Shopify and try to preview it, no text displays. Is there anything wrong in this statement?

{% if requires_shipping %}
	{% for line in line_items %}  
		{% for tag in product.tags %}
    		{% if tag == 'presale' %}
				PRESALE MESSAGE TEXT.
			{% else %}
				Items normally ship within 1-2 business days.
			{% endif %}
		{% endfor %}
	{% endfor %}
{% else %}
    Email us with further questions.
{% endif %}

Appreciate your help and looking forward to your response.

0 Likes
Oswald
Shopify Staff
Shopify Staff
93 0 25

Hey Port5,

This is Oswald, a Guru here at Shopify!

I been doing a couple of tests and the following worked for me!

{% if requires_shipping %}
  {% for line in line_items %}
   {% for tag in line.product.tags %}
    {% if tag contains "presale" %}
       PRESALE MESSAGE TEXT.
       {% else %}
         Items normally ship within 1-2 business days.
       {% endif %}
   {% endfor%}
  {% endfor%}
{% else %}
  Please email us with any further questions.
{% endif %}

Hope the information above helps!

Cheers!

Oswald | Shopify Guru

0 Likes
Jason
Shopify Expert
10037 119 1873

Just a small note on the above - if the product has multiple tags the else message will show many times. Best adjust this section:

{% for tag in line.product.tags %}
  {% if tag contains "presale" %}
    PRESALE MESSAGE TEXT.
  {% else %}
    Items normally ship within 1-2 business days.
  {% endif %}
{% endfor%}

into something more like this:

{% if line.product.tags contains 'presale' %}
  PRESALE MESSAGE TEXT.
{% else %}
  Items normally ship within 1-2 business days.
{% endfor%}

^ this assumes the tag equals presale.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
James_Zedd
Shopify Partner
43 0 2
{% if line.product.tags contains 'presale' %}
  PRESALE MESSAGE TEXT.
{% else %}
  Items normally ship within 1-2 business days.
{% endfor%}

Wanted to point out the closing tag should be {% endif %} instead of {% endfor%}

0 Likes
James_Zedd
Shopify Partner
43 0 2
{% if line.product.tags contains 'presale' %}
  PRESALE MESSAGE TEXT.
{% else %}
  Items normally ship within 1-2 business days.
{% endfor%}

Wanted to point out the closing tag should be {% endif %} instead of {% endfor%}

0 Likes
MatthewUpton
New Member
1 0 0

I am trying to do the same thing and even with the correction to the end tag, thanks to @James_Zedd but it is still not triggering the message when an order included a 'haulaway' tagged item in cart.

 

{% if line.product.tags contains 'haulaway' %}
<p style="font-weight: bold; font-size: 18px;"> Haul Away Notes </p>
<p><strong>Conditions:</strong></p>
<ol>
<li>
<p>All pre-existing furniture to be removed must be at the ground level, ready for pickup</p>
</li>
<li>
<p>All pre-existing furniture to be removed must be disassembled PRIOR TO the date of the pickup</p>
</li>
<li>
<p>All pre-existing furniture to be removed must be from the same address as the delivery</p>
</li>
<li>
<p>All pre-existing furniture to be removed must be in good sanitary and non-hazardous conditions</p>
</li>
</ol>
{% else %}
Reply to this email us if you have any questions
{% endif %}

 

 

0 Likes
cmoriarty
New Member
2 0 0

Has anybody gotten this to work? I have the following code and basically, it is all simply bypassed the entire For Loop. Here's the code:

{% if requires_shipping %}
Hi {{ customer.first_name }},
Some important reminders:
<ul>
<li>

{% for tag in line.product.tags %}
{% if tag contains "presale" %}
PRESALE MESSAGE TEXT.
{% else %}
Items normally ship within 1-2 business days.
{% endif %}
{% endfor%}

<a href="https://teddythedog.com/collections/pick-of-the-litter">Pick of the Litter (POTL) </a>designs are always PRE-ORDER; they do not ship right away. The beauty of a POTL is it's when you can get a new design on the greatest assortment of items. Typically the window to order is one week. POTL close and ship dates are always <a href="https://teddythedog.com/pages/teddys-pick-of-the-litter-info">posted on our site</a> and the product's pages.</li>
<li>

 

The <li> section only contains the text after the 'endfor' command and nothing in side ofit.

Thanks for your help!

0 Likes
cmoriarty
New Member
2 0 0

Answered my own question. My code is below. Two quick notes:

1. Because you iterate through every line in order, it's best to set have the for loop set a bool and then base your code off of the bool.

2. don't forget the .tags should be 'Contains' and not '==' unless you're sure the product contains only one tag. Here's what's worked for me:

 

     {% assign myBool = false %}


     {% for line in line_items %}
          {% if line.product.tags contains 'someTag' %}
               {% assign myBool = true %}
               {% break %}.  -Note: This keeps breaks the for loop if it finds a true statement so your bool doesn't get overwritten. 
          {% else %}
               {% assign myBool = false %}
          {% endif %}
     {% endfor %}
{% if myBool == true %}
     Message if myBool is True
{% else %}
      Message if myBool is False.
{% endif %}

 

Hope this works for anybody who needs it. 

0 Likes