Add product metafield to email order confirmation

Hi!
I have read all the treads about this but cant make it work :))

I have an produkt metafields, witch is named: custom.event_info_test

I want to show this in the order confirmation email… But how?

Hi @annenetmine ,

To show product metafield value in your order confirmation email you need to edit the “Order Confirmation” template.

To access “Order Confirmation” template follow these steps -

  1. Go to Shopify admin > Settings > Notifications
  2. Select the “Customer Notifications” section
  3. Click on the “Order confirmation”
  4. Click on the “Edit code” to open the template

Now, here in the template you can add you metafield to be displayed.

For editing the liquid code, here is reference video link to edit printing slip template to display custom field value of the product: https://www.youtube.com/watch?v=aMN49-AZLYI

This will give you an idea of how to edit template and use liquid variables.

Please let me know if more details are needed.

Thanks & Regards,

Vivek

You can access product metafields with the line.product.metafields variable.

Example:

{% for line in line_items %}

{{ line.product.metafields }}

{% endfor %}

To show a specific metafields, you can use this variable: {[ line.product.metafields.NAMESPACE.KEY }}

So, assuming “custom” is the namespace and “event_info_test” is the key, you could access that metafield with this variable:

{[ line.product.metafields.custom.event_info_test }}

Reference docs:

Oh! I had tried to use that varible before but i havent use the “{% for line in line_items %}” to check before. Now it works great!

Thank you so much! Really appriciate it- :smiley:

But now I have a follow-up problem. I have several variations of this product and I only want to read this metafield once per product in the email, not once per variant. How can I adjust this?