Display message when metafield contains

Hi all,

Does anyone know of a way that i can display a plain text message on the customer’s email notification when a metafield contains a certain value.

The metafield i have set up is a single line text with 3 preset options.

Any help is much appreciated! :blush:

Hi @LittlePaddocks

You can use the code below as reference.

  1. From your Admin Page, click Online Store > Settings on your left hand corner
  2. Go to Notifications, place the code below anywhere inside the {% for line in subtotal_line_items %} and {% endfor %}

Note: Change the product.metafields.custom.title, to the namespace and key you have, and add line. before it

{% case line.product.metafields.custom.title | metafield %}
{% when "title1" %}
put your text here...
{% when "title2" %}
put your text here...
{% when "title3" %}
put your text here...
{% endcase %}

Brilliant, I’ll give that a go!

Thank you for your help :slightly_smiling_face:

Hi, i’m just trying to implement this code in my notification now.

I’ve edited it to this

{% case order.metafields.custom.select_delivery_status | metafield %}
{% when “left_in_safe_place” %}
Message 1
{% when “delivered_to_recipient” %}
Message 2
{% when “redelivery” %}
Message 3
{% endcase %}

Am i correct to use _ for spaces in the names of each option?

Also the metafield i’m using is an order metafield. Not product.

Does it make a difference where i place the code, as i would like to add it to the body or just below (before the view my order & visit our store buttons). But wasn’t sure if this was why it was not working?

Thanks in advance for your advice.

Heres the metafield in my admin for reference…

Hi @LittlePaddocks

It does matter on where you are placing the code, make sure you are pasting it inside the {% for line in subtotal_line_items %} and {% endfor %}

I edited the code below, I change the order to line.product, and your when statement

{% case line.product.metafields.custom.select_delivery_status | metafield %}
{% when "left in safe place" %}
Message 1
{% when "delivered to recipient" %}
Message 2
{% when "redelivery" %}
Message 3
{% endcase %}

Hi, sorry i should have stated originally that i am looking to add this feature into the ‘local delivery delivered’ and ‘shipping confirmation’ emails.

I looked and cant seem to find {% for line in subtotal_line_items %} in either of those emails. Just the order confirmation. Would this be correct?

Thanks.