Shopify themes, liquid, logos, and UX
Hi All,
I need to display different text on a shipping notification, depending on if an order contains a tag or not.
I thought I had it figured out, but this is now not displaying any text, as if neither of my arguments are true.
Can anyone point me in the direction of where I'm going wrong?
{% if fulfillment.item_count == item_count %}
{% capture email_title %}Your order is on the way{% endcapture %}
{% capture email_body %}{% for tag in orders.tags %} {% if tag == 'National Delivery' %}
Your order is on the way. Our courier will deliver your order tomorrow. <br/><br/>To track your order, please click 'View Your Order' below.
{% elsif tag == 'Local Delivery' %}
Your order is on the way. Our driver will deliver your order today. <br/><br/>At Arrow Fresh, we do everything we can to protect the environment. Please consider returning any packaging to us, by leaving it outside when we deliver your next order.
{% endif %}
{% endfor %}
{% endcapture %}
Solved! Go to the solution
This is an accepted solution.
So you'll want to approach it kind of like this. You don't use the order keyword when in notification templates. It would just be tags. So make a forloop at the top of your file to go through your tags and assign variables to true based on conditions:
{% for tag in tags %}
{% assign tag_handle = tag | handleize %}
{% if tag_handle == "local-delivery" %}
{% assign local_delivery = true %}
{% elsif tag_handle == 'national-delivery' %}
{% assign national_delivery = true %}
{% endif %}
{% endfor %}
So above we're looping through the tags. We assign tag_handle to equal the tag's handle by using a handleize filter. This essentially downcases the tag and adds hyphens where spaces would be. For example, "Local Delivery" would be "local-delivery" -- We do this in case any typos are made along the way -- "lOcAl DeLivEry" would also return "local-delivery".
Then we say if the tag_handle == 'local-delivery' or if it == "national-delivery" to create a variable either called "local_delivery" or "national_delivery" and set them to true if one of those tags exists. Lower in your file, where you capture the email body, you would just use an if statement to check for the variables and place different text in the capture. Like this, here's the whole first segment:
{% for tag in tags %}
{% assign tag_handle = tag | handleize %}
{% if tag_handle == "local-delivery" %}
{% assign local_delivery = true %}
{% elsif tag_handle == 'national-delivery' %}
{% assign national_delivery = true %}
{% endif %}
{% endfor %}
{% if fulfillment.item_count == item_count %}
{% capture email_title %}Your order is on the way{% endcapture %}
{% capture email_body %}
{% if national_delivery %}
Your order is on the way. Our courier will deliver your order tomorrow. <br/><br/>To track your order, please click 'View Your Order' below.
{% elsif local_delivery %}
Your order is on the way. Our driver will deliver your order today. <br/><br/>At Arrow Fresh, we do everything we can to protect the environment. Please consider returning any packaging to us, by leaving it outside when we deliver your next order.
{% endif %}
{% endcapture %}
That should work for you.
This is an accepted solution.
So you'll want to approach it kind of like this. You don't use the order keyword when in notification templates. It would just be tags. So make a forloop at the top of your file to go through your tags and assign variables to true based on conditions:
{% for tag in tags %}
{% assign tag_handle = tag | handleize %}
{% if tag_handle == "local-delivery" %}
{% assign local_delivery = true %}
{% elsif tag_handle == 'national-delivery' %}
{% assign national_delivery = true %}
{% endif %}
{% endfor %}
So above we're looping through the tags. We assign tag_handle to equal the tag's handle by using a handleize filter. This essentially downcases the tag and adds hyphens where spaces would be. For example, "Local Delivery" would be "local-delivery" -- We do this in case any typos are made along the way -- "lOcAl DeLivEry" would also return "local-delivery".
Then we say if the tag_handle == 'local-delivery' or if it == "national-delivery" to create a variable either called "local_delivery" or "national_delivery" and set them to true if one of those tags exists. Lower in your file, where you capture the email body, you would just use an if statement to check for the variables and place different text in the capture. Like this, here's the whole first segment:
{% for tag in tags %}
{% assign tag_handle = tag | handleize %}
{% if tag_handle == "local-delivery" %}
{% assign local_delivery = true %}
{% elsif tag_handle == 'national-delivery' %}
{% assign national_delivery = true %}
{% endif %}
{% endfor %}
{% if fulfillment.item_count == item_count %}
{% capture email_title %}Your order is on the way{% endcapture %}
{% capture email_body %}
{% if national_delivery %}
Your order is on the way. Our courier will deliver your order tomorrow. <br/><br/>To track your order, please click 'View Your Order' below.
{% elsif local_delivery %}
Your order is on the way. Our driver will deliver your order today. <br/><br/>At Arrow Fresh, we do everything we can to protect the environment. Please consider returning any packaging to us, by leaving it outside when we deliver your next order.
{% endif %}
{% endcapture %}
That should work for you.
Lol, only been about a year. Glad it helped : )
I need help customizing an order notification template similar to this inquiry.
Hi @Ninthony! thank you for an excellent breakdown.
for the most part this is working great. I have some orders that have not been tagged. they are basically "default" or "standard"
I want to set it up to say:
{% for tag in tags %}
{% assign tag_handle = tag | handleize %}
{% if tag_handle == "wholesale" %}
{% assign wholesale = true %}
{% elsif tag_handle != 'wholesale' %}
{% assign standard = true %}
{% endif %}
{% endfor %}
{% capture email_title %}Thank you for your order{% endcapture %}
{% capture email_body %}
{% if wholesale %}
<p>This is a wholesale order</p>
{% elsif standard %}
Hi {{ customer.first_name }},
The wholesale emails are working, but the standard is now. Can this be written with a "not" statement? or do I need to have tags on every order?
So when I wrote this, I should have initialized everything to false. Like this:
{% assign wholesale = false %}
{% for tag in tags %}
{% assign tag_handle = tag | handleize %}
{% if tag_handle == "wholesale" %}
{% assign wholesale = true %}
{% endif %}
{% endfor %}
{% capture email_title %}Thank you for your order{% endcapture %}
{% capture email_body %}
{% if wholesale %}
<p>This is a wholesale order</p>
{% else %}
Hi {{ customer.first_name }},
So here we assign wholesale to false initially. Then we loop through the tags, if the wholesale tag is present we assign wholesale to true. Then further down the file you can just check {% if wholesale %} to output your wholesale message, and then just keep what you want for every other customer in the {% else %} portion instead of using an {% elsif %}.
That did the trick! thank you again! your posts have been exceptional.
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025