Solved

Change Notification Based On Order Tag

LeedsAF
Visitor
3 0 0

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 %}

 

Accepted Solution (1)

Ninthony
Shopify Partner
2330 350 1024

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.

If my solution helped you, please like it and accept it as the solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish 😄

View solution in original post

Replies 7 (7)

Ninthony
Shopify Partner
2330 350 1024

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.

If my solution helped you, please like it and accept it as the solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish 😄
LeedsAF
Visitor
3 0 0

Thanks @Ninthony 

This worked perfectly. (Sorry for the late reply!)

Ninthony
Shopify Partner
2330 350 1024

Lol, only been about a year. Glad it helped : )

If my solution helped you, please like it and accept it as the solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish 😄
msmarbo
Visitor
1 0 0

I need help customizing an order notification template similar to this inquiry.

GFW-webAdmin
Shopify Partner
17 1 4

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?

Ninthony
Shopify Partner
2330 350 1024

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 %}.

If my solution helped you, please like it and accept it as the solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish 😄
GFW-webAdmin
Shopify Partner
17 1 4

That did the trick! thank you again! your posts have been exceptional.