Insert metafields in order email notifications

Could somebody please help me with the correct code to pull a metafields value into my order emails.

I am talking about metafields as in: http://docs.shopify.com/themes/liquid-variables/metafield

NOT meta seo tags

The codes I have tried are:

{{ product.metafields.shortdesc[‘shortdescr’] }}

{{ line.metafields.shortdesc[‘shortdescr’] }}

{{ line.product.metafields.shortdesc[‘shortdescr’] }}

Within the following:

{% for line in line_items %}{{ line.quantity }}x {{line.title }} {{ line.product.metafields.shortdesc[‘shortdescr’] }} for {{ line.price | money }} each (sku: {{ line.sku }}) {{ line.line_price | money_with_currency }}
{% endfor %}

If somebody could give me some advice it would be very much appreciated!

Thanks

So funny that you just posted this Hazel, I was dealing with this all day today without any positive results, so I’m interested in a solution here as well!

Thanks

You can refer to line item properties like so:

line.properties['super-awesome-property']

So it would look like this:

{% for line in line_items %}{{ line.quantity }}x {{line.title }} {{ line.properties['shortdescr'] }} for {{ line.price | money }} each (sku: {{ line.sku }})  {{ line.line_price  | money_with_currency }}
{% endfor %}

I’m just adding to this thread because it’s the first result that comes up when searching for “product metadata email notification shopify”. The solution above didn’t work for me, but in my use case where I have numerous Product level metafields under a specific namespace the following worked for me -

https://community.shopify.com/c/Shopify-APIs-SDKs/How-to-add-metafield-to-check-for-specific-product-type-like/td-p/451980

{{ line.product.metafields.namespace.key }}

Hi all,

just wanted to share that for me, accessing variant metafields in the Shopify Emails work fine:

{%if line.variant.metafields.info.downloadlink%}
        Download Now!
   {%endif%}

This is within the line_item forloop

Hope this helps,

cheers

Hi there,

I’m now trying to get this done for hours, but no matter what I do, the output will always be empty…

I’m using the new metaobject and reference the metaobject “vendor” in products. I need to show the vendor information in Email confirmations.

this is one (of the many) I’ve tried:

{% if product.metafields.custom.vendor.value.name.value != '' %}
  {{ product.metafields.custom.vendor.value.name.value }} 
{% endif %}

also:

{% if line.product.metafields.custom.vendor.value.name.value != '' %}
  {{ line.product.metafields.custom.vendor.value.name.value }} 
{% endif %}

I would be grateful for any help!

thx!

{% if line.product.metafields.custom.vendor.value != ‘’ %}

That’s the right syntax up there. But guess what? It doesn’t work in the emails. The metafield data seems to be absent in the emails. The same code cut and pasted into one of the theme liquid pages works. I was working on this problem just yesterday.

Same issue here. Can’t seem to access variant metafields in email templates. Can get the product metafields just fine, but not the variants.

Hey @BattalionBen I am having difficulty with even pulling the product metafields into the email template - could you post what worked for you? (I know it was a while ago) thanks!

Same here. No way to get the URL from the GID with Liquid. So we cannot reference a product in the Notifications. Any leads on this ?

Ok so in my understanding it is simply not possible to have a referenced product in an Notification. The Problem is for emails only only the following format works:

{{ line.product.metafields.custom.productReference }}
→ This will deliver the GID like: gid://shopify/Product/12345678
→ This is not an object as for templating syntax. Therefore we can not access value. And therefor there is no way to access the URL or title

If someone has another opinion about this let me know.

I am also adding my feedback, because of checking how to show metafields I have on the order directly, via a custom extension.

And it seems to be pretty easy, directly on the order metafields:

{% if metafields.yourAppNamespace.deliveryInstructions %}
  #### Delivery instructions
  {{ metafields.yourAppNamespace.deliveryInstructions }}
  

{% endif %}

However I could not really find the documentation for for metafields in notifications variables reference

Same problem as well. We need to be able to see the:

In the staff email notification for new orders configured here:

If anyone figures out these metadata tags or steps to include this metadata, I would love to hear about it!

I hope you can help me.

I created a custom notification and it work perfectly apart from the information I have in the order metafields.

Can you understand and help me fix why my headers do not show and why the information in my Metafields is not pulling into my notification?

{% capture email_body %}
{% if item_count > 1 %}
{% endif %}
{% endcapture %}

@import url('[https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap](https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap)'); h1{font-family: 'Times New Roman', Times, serif; font-size: 16px; letter-spacing: 0.02em; line-height: normal; color: #ffffff; font-weight: 500; margin: 0;} h3{font-family: Arial, Helvetica, sans-serif; font-size: 16px; text-transform: uppercase; line-height: normal; color: #ffffff; font-weight: 400; margin: 0;} p{font-family: Arial, Helvetica, sans-serif; font-size: 16px; text-transform: uppercase; line-height: normal; color: #ffffff; font-weight: 400; margin: 0;} .ship p{font-family: Arial, Helvetica, sans-serif; font-size: 14px; text-transform: uppercase; line-height: 26px; color: #ffffff; font-weight: 400; margin: 0;} .button a{font-family: Arial, Helvetica, sans-serif; font-size: 18px; line-height: normal; font-weight: 400; margin: 0; color: #171717; text-transform: uppercase; text-decoration: none;} .button{background-color: #ffffff; width: 380px; height: 74px;} .button1 a{font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: normal; font-weight: 600; text-transform: uppercase; margin: 0; color: #000000; text-decoration: none;} .button1{background-color: #000000; width: 180px; height: 47px;} .mobimg{display: none;} @media screen and (max-width: 639px) { .container{width: 100% !important; max-width: 100% !important;} .body{width: 90% !important; max-width: 90% !important;} } @media screen and (max-width: 450px) { }
{% for line in subtotal_line_items %} {% if line.variant_title != 'Default Title' %} {% if line.draft_order.custom.property

%}

{% endif %} {% if line.order.custom.criteria %} {% endif %} {% endif %} {% endfor %}

INVOICE NUMBER: {{ name }}

The following invoice has been raised by Bourne & Co Estates Ltd

{% if custom_message != blank %}{{ custom_message }}{% elsif reserve_inventory_until %}{{ email_body }}{% endif %}

PROPERTY:

{{draft_order.custom.property}}

INVOICE CRITERIA:

{{ order.custom.payment_collection_method }}

INVOICE SUMMARY:

{% for line in subtotal_line_items %}{% if line.quantity < line.quantity %} {% capture line_display %} {{ line.quantity }} of {{ line.quantity }} {% endcapture %} {% else %}{% assign line_display = line.quantity %}{% endif %}

{{ line.title }}

{% if line.final_line_price > 0 %}{{ line.final_line_price | money }}{% else %} Free{% endif %}

{% endfor %}
{% assign order_discount_count = 0 %} {% assign total_order_discount_amount = 0 %} {% assign has_shipping_discount = false %}

{% for discount_application in discount_applications %}
{% if discount_application.target_selection == ‘all’ and discount_application.target_type == ‘line_item’ %}
{% assign order_discount_count = order_discount_count | plus: 1 %}
{% assign total_order_discount_amount = total_order_discount_amount | plus: discount_application.total_allocated_amount %}
{% endif %}
{% if discount_application.target_type == ‘shipping_line’ %}
{% assign has_shipping_discount = true %}
{% assign shipping_discount = discount_application.title %}
{% assign shipping_amount = discount_application.total_allocated_amount %}
{% endif %}
{% endfor %}

{% if current_total_duties %} {% endif %}

SUBTOTAL: {{ subtotal_price | plus: total_order_discount_amount | money }}

DUTIES: {{ current_total_duties | money }}

TAX: {{ tax_price | money }}

TOTAL: {{ total_price | money }}

BILLING ADDRESS

{{ billing_address | format_address }}

THIS INVOICE IS DUE FOR PAYMENT ON: {% for line in subtotal_line_items %} {% if line.variant_title != 'Default Title' %} {{ custom.payment_collection_method }} {% endif %} {% endfor %}

PAY THIS INVOICE

BOURNE & CO ESTATES LTD

11A FRONT STREET, LANCHESTER, DURHAM, DH7 OLA

+44 (0)1207 529 900 | info@bournenco.com

Sorry, tricky to help.

Are you talking about the “custom_message”? Then I would check where you “saved” this, and try to access it correctly over “metafields…” as I posted in my above example.

Not sure what your issue is regarding the header, maybe add a height to the image.

Can’t really help you out from here.