Re: Adding weight to product page

Solved

How can I correctly display product weight in ounces on my product pages?

lisajocelynco
New Member
10 0 0

Hi There - I need to add SKU & Weight to my product pages. I looked in this forum for code examples and added it. The SKU is working just fine but the weight is not... for starters, my unit is in oz. but it is showing lbs - so everything is 0 lbs. How do I get the weight to show correctly?

 

This is my code (in the main-product.liquid)

{%- when 'title' -%}
<h1 class="product__title" {{ block.shopify_attributes }}>
{{ product.title | escape }} </h1>
{% assign current_variant = product.selected_or_first_available_variant %}
<span class="variant-sku">SKU: {{ current_variant.sku }}</span><br>
Weight: {{ variant.weight | weight_with_unit }}

 

This is the page to see what I'm talking about, weight should be 5.0 oz.

https://jocelyncowholesale.com/products/the-luxe-collection-hardwood-smoked-summer-sausage

 

TIA!

 

Accepted Solution (1)
William_H
Shopify Partner
30 3 6

This is an accepted solution.

Try using this liquid variable instead: {{ product.variants.first.weight | weight_with_unit }}

Here is the full revised code:

 

{%- when 'title' -%}
<h1 class="product__title" {{ block.shopify_attributes }}>
{{ product.title | escape }} </h1>
{% assign current_variant = product.selected_or_first_available_variant %}
<span class="variant-sku">SKU: {{ current_variant.sku }}</span><br>
Weight: {{ product.variants.first.weight | weight_with_unit }}

View solution in original post

Replies 5 (5)

William_H
Shopify Partner
30 3 6

Try double checking what the default unit of your store is in /admin/settings/general. I'm guessing it is set to lbs. 

lisajocelynco
New Member
10 0 0

OMG I didn't even think of that! So that part worked (thank you) but the weight is still showing 0.0 oz and should say 5.0 oz... any ideas?

William_H
Shopify Partner
30 3 6

This is an accepted solution.

Try using this liquid variable instead: {{ product.variants.first.weight | weight_with_unit }}

Here is the full revised code:

 

{%- when 'title' -%}
<h1 class="product__title" {{ block.shopify_attributes }}>
{{ product.title | escape }} </h1>
{% assign current_variant = product.selected_or_first_available_variant %}
<span class="variant-sku">SKU: {{ current_variant.sku }}</span><br>
Weight: {{ product.variants.first.weight | weight_with_unit }}
lisajocelynco
New Member
10 0 0

Yep that did it! Thanks Rock Star 🙂

Ralph-Jr
Visitor
1 0 0

I had to look around for this code for a while now. 🙂

I have used your code in a 'custom liquid' in the product default template, than in main-product.liquid:

<span style="font-size: 12px;">
{% assign current_variant = product.selected_or_first_available_variant %}
Weight: {{ product.variants.first.weight | weight_with_unit | upcase }}
</span>

 

This works as well.

Thank you, William.