Craft theme. How to show weight in every products and total weight in cart?

Craft theme. How to show weight in every products and total weight in cart?

Booomas
Tourist
5 0 1

Hi,

How to show weight in every products and total weight in cart for Craft theme?

I spend few days for trying to do this. But any code I found is not worked. Got really tired of this.

 

Can any one help to fix this?
Thank you in advance.

 

 

Replies 8 (8)

Asad24
Shopify Partner
180 36 33

To display total weight on cart page add this code in your liquid file which is responsible for displaying cart page

{% assign totalWeight = 0 %}
{% for item in cart.items %}
{% assign productWeight = item.variant.weight | weight_with_unit %}
{% assign productQuantity = item.quantity %}
{% assign productTotalWeight = productWeight | times: productQuantity %}
{% assign totalWeight = totalWeight | plus: productTotalWeight %}
{% endfor %}

<p>Total Cart Weight: {{ totalWeight }}</p>

banned
Booomas
Tourist
5 0 1

Hi Asad,

Thanks for the help. However, it only shows the number: Total Cart Weight: 2
And it shows in cart on the left side. Should be on the right.

 

Is there any way to show weight in every item card? Not only the total in the cart?

Asad24
Shopify Partner
180 36 33

Yes you can show weight on each produt with unit by using this variable 
{{ selected_variant.weight | weight_with_unit }}

banned
Booomas
Tourist
5 0 1

Appears, but only zeros. Does not show weights.
And shows in the bottom left corner.
It should be displayed in a visible place, at the bottom of the size variations or similar.

I don't really understand coding. I am new to Shopify. So maybe I'm not uploading it where it should be.

Booomas
Tourist
5 0 1

Is there a way to make it at least add "kg" and show not only whole numbers after the decimal point?

Untitled.png

Booomas
Tourist
5 0 1

Untitled1.png

Asad24
Shopify Partner
180 36 33

If you'd like me to provide a more thorough examination of your store, I'll require collaborator access to effectively meet your needs.

banned
envioes
Visitor
1 0 0

How to make a "real-time" update of "Total Cart Weight" in this code?

For example, if you add quantity for the product in the cart, the total cart weight is not updated and you need to refresh the page. How to correct it?