Shopify themes, liquid, logos, and UX
Is it possible to insert the value of a products weight into the products description using code? This way the weight of the product is visible information to the customer before they purchase and it would make things a lot quicker as there would be no need to manually include the weight in each and every products description, as this would be done automatically.
The theme being used is Debut.
Hey @somersetfoodie,
You need to change the product page template liquid file.
You can use the following code to display product weight.
Weight: {% for variant in product.variants %}{{variant.weight | weight_with_unit }}{% endfor %}
Hope this will work.
Thanks!
Thanks for the quick response! Where in the code structure should I use the code you provided? This is how the product.liquid code looks right now:
{% comment %}
The contents of the product.liquid template can be found in /sections/product-template.liquid
{% endcomment %}
{% section 'product-template' %}
{% section 'product-recommendations' %}
{% if collection %}
<div class="text-center return-link-wrapper page-width">
<a href="{{ collection.url }}" class="btn btn--secondary btn--has-icon-before return-link">
{% include 'icon-arrow-left' %}
{{ 'products.product.back_to_collection' | t: title: collection.title }}
</a>
</div>
{% endif %}
<script>
// Override default values of shop.strings for each template.
// Alternate product templates can change values of
// add to cart button, sold out, and unavailable states here.
theme.productStrings = {
addToCart: {{ 'products.product.add_to_cart' | t | json }},
soldOut: {{ 'products.product.sold_out' | t | json }},
unavailable: {{ 'products.product.unavailable' | t | json }}
}
</script>
{% assign current_variant = product.selected_or_first_available_variant %}
<script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "Product",
"name": {{ product.title | json }},
"url": {{ shop.url | append: product.url | json }},
{%- if product.featured_media -%}
{%- assign media_size = product.featured_media.preview_image.width | append: 'x' -%}
"image": [
{{ product.featured_media | img_url: media_size | prepend: "https:" | json }}
],
{%- endif -%}
"description": {{ product.description | strip_html | json }},
{%- if current_variant.sku != blank -%}
"sku": {{ current_variant.sku | json }},
{%- endif -%}
"brand": {
"@type": "Thing",
"name": {{ product.vendor | json }}
},
"offers": [
{%- for variant in product.variants -%}
{
"@type" : "Offer",
{%- if variant.sku != blank -%}
"sku": {{ variant.sku | json }},
{%- endif -%}
"availability" : "http://schema.org/{% if product.available %}InStock{% else %}OutOfStock{% endif %}",
"price" : {{ variant.price | divided_by: 100.00 | json }},
"priceCurrency" : {{ cart.currency.iso_code | json }},
"url" : {{ shop.url | append: variant.url | json }}
}{% unless forloop.last %},{% endunless %}
{%- endfor -%}
]
}
</script>
Hey @somersetfoodie,
Go to Sections/product-template.liquid file. You will get a description code there just paste given code there and see where it appears.
Move that code in your desired place.
Thanks!
Thanks, this has worked! It is currently displaying the weight in lbs when I would like it display kg. Is it possible to change which unit of weight the code displays?
Hey @somersetfoodie,
Please edit the product and check the setting of the product weight in the admin. It must be in KG.
Because if you see the code, it is dynamic. It will automatically take weight measurements for the product.
So please check in the admin.
Thanks!
Hi
I follow the instruction and although I have gr. as weight metric for the products in the Admin, the weight is displayed as kg. in the product page.
Do you know how I can show gr. instead of kg in the product page?
Thanks
Dear Sir
is there is away to show weight when variant chosen
not display all variants weight as the photo
Hi, I'm trying to do the same, but I need the weight to change according to the variant selected on the product page (I have between 3 and 12 variants on each page.) Is there a way to do this?
Thanks!!
Are you ready to take your business to the next level? Look no further than the latest ...
By SarahF_Shopify Apr 15, 2024We’re keeping the ball rolling to make sure you’re always ahead of the game. So buckle ...
By JasonH Apr 8, 2024Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024