I want to add data from two Product fields to the line item listing in the order confirmation email:
- Date: This comes from a simple Product metafield called class_date_and_time. The following code works as expected and I can successfully access and display the line_date variable in my email (notice that .value is not appended to the access path):
{% assign line_date = line.product.metafields.custom.class_date_and_time | date: '%b %d, %Y' %}
- Location: This comes from a Product metafield also, but the metafield’s value is a Location metaobject value. I need to access Location.name, but it does not seem to work. Here is my code (I have tried every variation of that line I could think of btw, all with no luck):
{% assign line_loc = line.product.metafields.custom.location.value.name.value %}
I also know that I can access the location metafield as an object. If I adjust the access path to reach just the location metafield (line.product.metafields.custom.location), the variable is assigned the Location metabobject (gid://shopify/Metaobject/xxxxxxxxxx). When I try to access Location.name is where things fall apart.
There are two differences that I can see, that might be important:
-
Date references a metafield which is a simple date-time value, while Location references a metafield who’s value is a metaobject. Below shows my custom data from the Product object:
-
[object].value does not seem to work here. Unlike in the theme code editor, .value results in an empty variable in the email editor. If I remove .value from the access path, the variable is properly assigned and I can display my data. I tested this on the Date variable.
Also, this exact code works perfectly in card-product.liquid, where I add data from the location metaobject to the product card.
{% assign loc = card_product.metafields.custom.location.value.name.value %}
So I suppose I have two questions:
- Why does .value not work in the email editor, but does in the code editor?
- If .value does not work in the email editor, how then can I access the Location name?
And I’m using the Dawn theme if that’s important.
I appreciate any insight on this one.
