Shopify themes, liquid, logos, and UX
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!
Solved! Go to the solution
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 }}
Try double checking what the default unit of your store is in /admin/settings/general. I'm guessing it is set to lbs.
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?
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 }}
Yep that did it! Thanks Rock Star 🙂
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.
Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025