Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Im trying to add the weight of each line item onto our packing slips but the weight variables always show as zero even though values have been set for the items.
If I use this:
{{ line_item.weight | weight_with_unit }}
it just shows as:
0 g
Ive also tried using both
{{ line_item.grams | weight_with_unit }}
and
{{ line_item.grams }}
and just get the same result.
Ive placed this within the main for loop as you can see here:
{% for line_item in line_items_in_shipment %}
<div class="flex-line-item">
<div class="flex-line-item-img">
{% if line_item.image != blank %}
<div class="aspect-ratio aspect-ratio-square" style="width: {{ desired_image_size }}px; height: {{ desired_image_size }}px;">
{{ line_item.image | img_url: effective_image_dimensions | img_tag: '', 'aspect-ratio__content' }}
</div>
{% endif %}
</div>
<div class="flex-line-item-description">
<p>
<span class="line-item-description-line">
{{ line_item.title }}
</span>
{% if line_item.variant_title != blank %}
<span class="line-item-description-line">
{{ line_item.variant_title }}
</span>
{% endif %}
{% if line_item.sku != blank %}
<span class="line-item-description-line">
{{ line_item.sku }}
</span>
{% endif %}
{{ line_item.weight | weight_with_unit }}
{% if line_item.weight != blank %}
<span class="line-item-description-line">
{{ line_item.weight | weight_with_unit }}
</span>
{% endif %}
</p>
</div>
<div class="flex-line-item-quantity">
<p class="text-align-right">
{{ line_item.shipping_quantity }} of {{ line_item.quantity }}
</p>
</div>
</div>
{% endfor %}
Anyone know how I can get it to show the correct values? Is there a different bit of liquid I need?
Thanks
It's line_item.grams https://shopify.dev/api/liquid/objects#line_item-grams
And please try to print your line item. It will help you to debug your issue.
{{ line_item | json }}
Thanks,
I tried doing {{ line_item | json }}
it gives me a server error when I try to preview it so I can't see the possible variables (shot attached)
Also, Ive found that if I use this code within
settings > shipping & delivery
it comes up empty or shows zero value.
If I use this code within
order printer > edit templates
then it works and shows me the weight however it doesn't work for the barcode for which Im using this code:
{{ line_item.barcode }}
You should check the liquid document at first
It should be
{{ line_item.variant.barcode }}
https://shopify.dev/api/liquid/objects#variant-barcode
thanks that seems to work now although I had checked that doc and tried it before, I must have tried it in the shipping settings rather than in order printer.
As with most things shopify there seems to be conflicting info all over as Ive seen it suggested to do this several different ways now
Did you ever find a solution? I'm trying to get the weight to display for each item on the packing slip, but they are all 0.0
Thanks!
Sorry, I cant remeber if I got this working or not, if the answers not in this thread then probably not. We use order printer Pro now and it was simple to setup all of this
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024