Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
Hi There,
I am trying to insert a product metafiled url link into email notifications.
Can anyone help me with the coding please?
oh sorry for that issue your i think your meta wrong bt can you please share store url so i will check and let you know
I am trying to insert a product metafiled url link into email notifications.
Keywords for logic: product and it's metafield property
In the notification image of it's code your trying to access a metafield(MF) by name directly but metafields only exist on other resources(products,collections,pages,etc) they are not global objects in liquid. Global metafields would cause issues in logic, namespace, and scope for instance a collection could also have the same MF and the system would have no idea whether it's the collection or a product it should look at..
https://shopify.dev/api/liquid/objects#metafield:~:text=attached%20to%20a%20parent%20object
https://shopify.dev/api/liquid/objects#metafield-access-metafields
Further in the area of notification you code shows you are dealing with a line item, line_item, and not products.
Line items are the purchase information for a variant of a product.
Line items do have a reference to the product it's based on. Then through the products it's metafield.
Note: in some areas line may be replace with line_item .
So going through the objects property chain: line.product.metafields.my_fields.product_link
{{ line.product.metafields.my_fields.product_link }}
To output the metafield url as an html link with custom text use the link_to filter:
https://shopify.dev/api/liquid/filters#link_to
{{ 'Link text' | link_to:line.product.metafields.my_fields.product_link }}
to output the metafield url as an html link with the url also as the text use the metafield_tag filter which automatically uses the metafield type to render html appropriate to the type.
https://shopify.dev/api/liquid/filters#metafield_tag
https://shopify.dev/api/liquid/filters#metafield_tag-url
{{ line.product.metafields.my_fields.product_link | metafield_tag }}
note: metafield_tag does not accept parameters to change the link text.
Contact paull.newton+shopifyforum@gmail.com for the solutions you need
Save time & money ,Ask Questions The Smart Way
Problem Solved? ✔Accept and Like solutions to help future merchants
Answers powered by coffee Thank Paul with a ☕ Coffee for more answers or donate to eff.org
Hi @PaulNewton , thank you so much. This is very helpful.
I've added in this code and i can see the text but no clickable link through the the metafield url