HELP! How to get Product Metafields from LineItem

Erodad
New Member
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

0 Likes
malalta
Shopify Partner
23 5 7

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.

0 Likes