In the Packaging slip template if i do <pre>{{ line_item.product | json }}</pre>it says null.
How could I get Product metafields of a line_item?
All results I can find say “line_item.product.metafields”, but product doesn’t exist at all.
A user is unable to access product metafields within a packaging slip template. When attempting to use line_item.product, it returns null.
Key Issue:
line_items_in_shipment in the Shipping and delivery → Edit packing slip templateline_item.product.metafields doesn’t work because line_item.product is unavailable in this contextDiagnosis:
line_item.product works in their setup when iterating through order.line_itemsSuggested Solution:
line_item.product.metafields likely apply to Order Printer App templates, not the built-in packing slip editorStatus: Unresolved - the user may need to switch tools to access the required metafield data.
In the Packaging slip template if i do <pre>{{ line_item.product | json }}</pre>it says null.
How could I get Product metafields of a line_item?
All results I can find say “line_item.product.metafields”, but product doesn’t exist at all.
Share more code.
Say, if you do this outside the {% for line_item in order.line_items %} … {% endfor %} loop, then it’s expected.
Because it works inside mine:
{% for line_item in line_items_in_shipment %}
{{ line_item.title }} {% if line_item.variant_title != blank %} {{ line_item.variant_title }} {% endif %} {% if line_item.sku != blank %} {{ line_item.sku }} {% endif %}
{% for group in line_item.groups %}
{% if group.deliverable? %}
<span class="line-item-description-line">
Für: {{ group.title }}
</span>
{% else %}
<span class="line-item-description-line">
Teil von: {{ group.title }}
</span>
{% endif %}
{% endfor %}
</p>
</div>
<div class="flex-line-item-quantity">
<p class="text-align-right">
{{ line_item.shipping_quantity }} von {{ line_item.quantity }}
</p>
</div>
I thought this is the default code
Use the </> button when pasting code – forum engine may break it otherwise, as happened with yours…
You can see the default if you click “Create template” and select “Packing slip” – it’s not like yours.
So where are you trying to paste you code?
It is from the Shipping and delivery → Edit packing slip template, I thought it’s de default code
Ah, you may also consider using Order printer App.
It may be that Shipping and delivery does not provide access to all information.
The forums search result may have referenced solutions for the “Order printer” app.
What do you mean by “Order printer App”?
This:
In the packing slip template the only way to access a product object is through a line item while you are looping over order.line_items. Outside of that loop, line_item isn’t defined, so {{ line_item.product }} will return nil.
A typical packing slip will look something like this:
{% for line_item in order.line_items %}
{{ line_item.title }}
{% if line_item.product %}
{{ line_item.product.metafields.custom.my_key }}
{% endif %}
{% endfor %}
A few things to keep in mind:
The product object is only available from a line item. You must be inside the for line_item in order.line_items loop to reference it.
line_item.product will be nil if the product has been deleted from your store or if the order contains a custom item. In that case there is no product metafield to read.
Replace custom.my_key with the namespace/key of the metafield you want to output. For example, if you have a metafield called packing_info in namespace details, the syntax would be line_item.product.metafields.details.packing_info.
If you need a product value on the packing slip but the product may be deleted later, consider copying the metafield value into the line item properties or note when the order is created. That way you can print it from line_item.properties instead of depending on line_item.product.
The code I had has ”for line_item in line_items_in_shipment”, and there product data doesn’t exist, I’ll try “for line_item in order.line_items”
use {{ line.product.metafields.NAMESPACE.KEY }} or {{ line_item.product.metafields.NAMESPACE.KEY }} depending on your variable names in the forloop tag.
If it’s a custom line item there is no product to reference, same if the product is deleted by time notification is sent.
Always check the friendly manual first
https://help.shopify.com/en/manual/fulfillment/setup/notifications/email-variables#:~:text=a%20single%20item.-,line.product.metafields,-Any%20metafields%20at
{{ line.product }} isn’t a defined variable, support wise it’s squirrelly since that’s what shopify’s defined.
But technically I think the product object should be usable and not just some limited list of product properties.
Thank you all for the responses, I made it work this way
{% for line_item in order.line_items %}
{% if line_item.product.metafields.custom.batch_numbers != blank %}
<span class="line-item-description-line">
{{ line_item.product.metafields.custom.batch_numbers }}
</span>
{% endif %}
{% endfor %}