Liquid, JavaScript, themes, sales channels
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
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024