Serve Order Line Item Metafield Values in Email Notification, Limited to Specific Fields

nlounsbury
Visitor
1 0 0
Has anyone succesfully setup a Shopify Flow order notification email that contained variables referencing SPECIFIC metafields from the line items? So far, I can get it to serve ALL metafields associated with the line item, but not just the specific ones we want displayed. We are also using Bonify Custom Fields for these specific fields which, again DO show up, but in case that impacts things. Here are the variables referenced so far, where ITEM DETAILS TESTING is the section serving the specific metafield and alleviates error when removed. Error screenshot attached.
 

<b>ORDER DETAILS</b>

Order ID: {{order.id}}

Order Number: {{order.name}}

Customer name: {{order.customer.displayName}}

Shopify customer id: {{order.customer.id}}

Customer company:

Customer email: {{order.email}}


<b>ITEM DETAILS</b>

{% for lineItems_item in order.lineItems %} {{lineItems_item.name}}{% endfor %}

{% for lineItems_item in order.lineItems %}

{% for metafields_item in lineItems_item.product.metafields %}

{{metafields_item.value}}

{% endfor %}

{% endfor %}


<b>ITEM DETAILS TESTING</b>

{% for metafields_item in lineitems_item.product.metafields %}

{% if metafields_item.key == "custom_fields.template" %}

{{ metafields_item.value }}

{% endif %}

{% endfor %}

Reply 1 (1)

DaveMcV
Shopify Staff
78 25 24

Hi

 

It looks like you're missing a loop around the last block of code. It should look like:

{% for lineItems_item in order.lineItems %}

{% for metafields_item in lineItems_item.product.metafields %}

{% if metafields_item.key == "custom_fields.template" %}

{{ metafields_item.value }}

{% endif %}

{% endfor %}

{% endfor %}

Also of note, the initial snippet you posted used the variable `lineitems_item` instead of `lineItems_item` (capitalization on the second `i` is mismatched) so that is fixed too.

 

Hope that helps!

DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.