thecatmelon
8/14/2015 - 6:07 PM

Calculate the total weight of the order for the order printer template

Calculate the total weight of the order for the order printer template

Order: Total weight

Loops through all the line items to calculate the total weight:

{% assign total_weight = 0 %}
{% for line in line_items %}
  {% assign total_weight = line.quantity | times: line.grams | plus: total_weight %}
{% endfor %}
Total weight : {{ total_weight | weight_with_unit }}

The weight_with_unit filter wasn't working for me so I did some cool filtery math stuff to get it to work.

Total weight : {{ total_weight | times: 2.20462262 | divided_by: 1000 | round: 1 }} {% if total_weight == 1 %}lb{% else %}lbs{% endif %}

Another add on to get the total number of items. Add this line into the for loop above, then output it

 {% assign total_items = line.quantity | plus: total_items %}
 Total Number of Pieces : {{ total_items }}