How can I code customer notifications for different home delivery emails?

Solved

How can I code customer notifications for different home delivery emails?

Kali_Curry
Excursionist
14 1 6

Hey!

 

     I am trying to update our Shopify notifications to send different Home Delivery emails, depending on certain criteria. I can't seem to get it to work and was hoping someone out there could help?

 

Just starting with the email subject line of the notification, here is what it currently is -

{% if attributes.Checkout-Method == "pickup" %}Order {{ name }} is ready for Pickup!{% elsif attributes.Checkout-Method == "delivery" %}Order {{ name }} is ready for Home Delivery!{% elsif order.note contains "dropship" or order.tags contains "dropship" %}Your order is almost on its way!{% else %}Order {{ name }} is on the way{% endif %}

 

I want to add another elsif statement to have different messaging if the order tags contains 'Mobile'. I have tried a few different ways to do this, such as -

 

{% if attributes.Checkout-Method == "pickup" %}Order {{ name }} is ready for Pickup!{% elsif attributes.Checkout-Method == "delivery" and order.tags contains “Mobile” %}Order {{ name }} has been delivered!{% elsif attributes.Checkout-Method == "delivery" %}Order {{ name }} is ready for Home Delivery!{% elsif order.note contains "dropship" or order.tags contains "dropship" %}Your order is almost on its way!{% else %}Order {{ name }} is on the way{% endif %}

 

But nothing I've tried has seemed to work. Does anyone have any suggestions?

Accepted Solution (1)
Kali_Curry
Excursionist
14 1 6

This is an accepted solution.

Thank you for your help, and the advice!

 

I'm not sure exactly why, but the code still wasn't working (and unfortunately I have a limit as to how many characters I can add, so I was unable to try the normalization coding).

 

I fiddled with it some more, and tested with other fields, and got it to work with this code - 

 

{% if attributes.Checkout-Method == "pickup" %}

Order {{ name }} is ready for Pickup!

{% elsif attributes.Custom-Attribute-2 contains "Mobile" %}

Order {{ name }} has been delivered!

{% elsif attributes.Checkout-Method == "delivery" %}

Order {{ name }} is ready for Home Delivery!

{% elsif order.note contains "dropship" or order.tags contains "dropship" %}

Your order is almost on its way!

{% else %}

Order {{ name }} is on the way

{% endif %}

 

Thank you again for your time and help!

View solution in original post

Replies 2 (2)

PaulNewton
Shopify Partner
7536 666 1595

Please use the format code and make effort to improve the readability with linebreaks and indentations when trying to work out syntax issues it will save you a ton of headaches and is a courtesy to contributors who are more likely to help you if you do.

If good formatting is causing linefeeds in your notifications use whitespace controls.

https://shopify.dev/api/liquid/basics#whitespace-control 

 

Here by formatting I can see it looks like your using special quotes instead of normal quotes around mobile

, i.e. Mobile vs "Mobile"

Current

 

{% if attributes.Checkout-Method == "pickup" %}
 Order {{ name }} is ready for Pickup!
{% elsif attributes.Checkout-Method == "delivery" and order.tags contains “Mobile” %}
 Order {{ name }} has been delivered!
{% elsif attributes.Checkout-Method == "delivery" %}
 Order {{ name }} is ready for Home Delivery!
{% elsif order.note contains "dropship" or order.tags contains "dropship" %}
 Your order is almost on its way!
{% else %}
 Order {{ name }} is on the way
{% endif %}

 

Should be

 

{% if attributes.Checkout-Method == "pickup" %}
 Order {{ name }} is ready for Pickup!
{% elsif attributes.Checkout-Method == "delivery" and order.tags contains "Mobile" %}
 Order {{ name }} has been delivered!
{% elsif attributes.Checkout-Method == "delivery" %}
 Order {{ name }} is ready for Home Delivery!
{% elsif order.note contains "dropship" or order.tags contains "dropship" %}
 Your order is almost on its way!
{% else %}
 Order {{ name }} is on the way
{% endif %}

 

 

 

Further is can help to either normalize tags to avoid non-matches due to typos by staff or apps.

This is  because of how the contains operator behaves mainly by being case sensitive or overmatching i.e. mobile == immobile.

Alternatively loop over them separately to do an exact|near match if there are other factors and set a match variable to true.

 

{%- assign tags == order.tags -%}
{%- assign search_string == "mobile" -%}
{%- assign tag_matched = false %}

{% for tag in tags %}
 {%- comment -%} normalize tag and string i.e. downcase, remove special characters like underscores, etc to do exact matches (==) to avoid false positives & negatives {%- endcomment -%}
  {%- assign normalized_tag == tag | downcase -%}
  {%- assign normalized_search_string == search_string | downcase -%}
  {% if normalized_tag == normalized_search_string  %}
    {%- comment -%} Set variables here {%- endcomment -%}
    {%- assign tag_matched = true %}
    {%- break -%}
  {% endif %}
{% endfor %}

 

 

{%- if tag_matched  -%}
 {%- assign mobile_order = true %}
{%- endif -%}

{% if attributes.Checkout-Method == "pickup" %}
 Order {{ name }} is ready for Pickup!
{% elsif attributes.Checkout-Method == "delivery" and mobile_order %}
 Order {{ name }} has been delivered!
{% elsif attributes.Checkout-Method == "delivery" %}
 Order {{ name }} is ready for Home Delivery!
{% elsif order.note contains "dropship" or order.tags contains "dropship" %}
 Your order is almost on its way!
{% else %}
 Order {{ name }} is on the way
{% endif %}

 

 

If your still experiencing occasional wierdness with this messaging you may want to to normalize/downcase the order.note or order.tags too. 

 

 

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org


Kali_Curry
Excursionist
14 1 6

This is an accepted solution.

Thank you for your help, and the advice!

 

I'm not sure exactly why, but the code still wasn't working (and unfortunately I have a limit as to how many characters I can add, so I was unable to try the normalization coding).

 

I fiddled with it some more, and tested with other fields, and got it to work with this code - 

 

{% if attributes.Checkout-Method == "pickup" %}

Order {{ name }} is ready for Pickup!

{% elsif attributes.Custom-Attribute-2 contains "Mobile" %}

Order {{ name }} has been delivered!

{% elsif attributes.Checkout-Method == "delivery" %}

Order {{ name }} is ready for Home Delivery!

{% elsif order.note contains "dropship" or order.tags contains "dropship" %}

Your order is almost on its way!

{% else %}

Order {{ name }} is on the way

{% endif %}

 

Thank you again for your time and help!