Insert Product Weight into Product Description

somersetfoodie
Tourist
8 0 2

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.

Replies 8 (8)

dmwwebartisan
Shopify Partner
12289 2547 3698

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!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app
somersetfoodie
Tourist
8 0 2

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>
dmwwebartisan
Shopify Partner
12289 2547 3698

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!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app
somersetfoodie
Tourist
8 0 2

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?

dmwwebartisan
Shopify Partner
12289 2547 3698

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!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com |  Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | #1 Product Filter & Search app on Shopify | The most powerful Shopify page builder app
grubio
Tourist
24 0 1

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

Huda-HN
Tourist
24 0 3

@dmwwebartisan 

Dear Sir 

is there is away to show weight when variant chosen

not display all variants weight as the photo

H-W
Tourist
3 0 2

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!!