HELP! How to get Product Metafields from LineItem

Erodad
Visitor
2 0 0

Hey guys and girls,

I am trying to read the metafields of a product that is referenced in a LineItem but it does not work.

What I am trying to do:

{{ line_item.product.metafields.global.id }}

 

But that doesnt work and the metafield does exist 100%!

 

Is it possible to somehow read the metafields of a product that is referenced in a LineItem?

 

Thanks for your help

Reply 1 (1)

malalta
Shopify Partner
23 5 15

Are you sure a metafield with the key "id" exists? If I recall correctly, Shopify require metafield keys to be at least 3 characters long...

To debug it, put this in your template temporarily to see what metafields are available :

 

<div hidden>
{% for field in line_item.product.metafields.global %}
  --
  Key: {{ field | first }}
  Value: {{ field | last }}
  --
{% endfor %}
</div>

 

 ...and then check your source code in the browser. Do you get anything back?

 

Cheers, Andrew.