Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Dear Shopify community,
for my order printer I would like to display the total weight of the entire order. I've checked the list of available variables (https://orderprinter.shopifyapps.com/259397/templates/variables), but there is no such variable.
Can you help?
Thanks
Pete
Solved! Go to the solution
This is an accepted solution.
Thanks for figuring this out!
As written, it failed to multiply the weight when a customer purchased multiple of the same item, so I changed it slightly:
{% assign total_weight = 0.00 %}
{% assign temp_weight = 0.00 %}
{% for line_item in line_items %}
{% assign temp_weight = line_item.weight | times: line_item.quantity %}
{% assign total_weight = total_weight | plus: temp_weight %}
{% endfor %}
Also, Shopify appears to store the weight in grams (even though it is entered in lbs), so where I needed the weight (to the nearest pound) displayed I used this:
{{ total_weight | divided_by: 453.5924 | round }} lbs
There's no solution for this problem? Hope somebody can help.
I understand this was from a while ago but I've also been trying to figure this out.
After an hour I've managed to get it working - SO IT CAN BE DONE..
I'll try to make it as easy as possible to understand.
1. First we create a total_weight variable and assign it to 0.00 outside of the for loop
2. Next we create a temp_weight variable and also assign it to 0.00
{% assign total_weight = 0.00 %}
{% assign temp_weight = 0.00 %}
{% for line in line_items %}
3. We then assign the line_item.weight to the temp_weight inside the for loop (this can be anywhere inside the for loop)
{% assign temp_weight = line_item.weight %}
4. Also inside the for loop just beneath the above code we assign the total_weight to be equal to the itself + the temp_weight
{% assign total_weight = total_weight | plus: temp_weight %}
5. Then we just display total_weight wherever we want it.
weight: {{ total_weight }}
Can confirm this works. Just needs to be setup correctly.
This is an accepted solution.
Thanks for figuring this out!
As written, it failed to multiply the weight when a customer purchased multiple of the same item, so I changed it slightly:
{% assign total_weight = 0.00 %}
{% assign temp_weight = 0.00 %}
{% for line_item in line_items %}
{% assign temp_weight = line_item.weight | times: line_item.quantity %}
{% assign total_weight = total_weight | plus: temp_weight %}
{% endfor %}
Also, Shopify appears to store the weight in grams (even though it is entered in lbs), so where I needed the weight (to the nearest pound) displayed I used this:
{{ total_weight | divided_by: 453.5924 | round }} lbs
Thanks to TenRivers for this as it helped me implement this for the new order printer app.
Just wanted to mention that for some users trying to add the order weight to the new order printer app by Shopify, you may need to use the line_item.variant.weight object.
Code used to calculate the weight of the order:
Thanks! Our store is only open one month of the year (it's a pre-order sale) so I haven't looked into the implications of the new order printer app yet, but thanks for the tweak to keep it working.
Hi,
Added this to the template for the new order printer app and it works.
However, it does not seem to work for different sku's.
Eg, if customer orders 2 different products, the weight of only one of the products is appearing?
As 2024 wraps up, the dropshipping landscape is already shifting towards 2025's trends....
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024