I am currently working on a clients Shopify site. They have requested that the product weight, for each individual product, is pulled through and displayed next to the price on collection pages.
I can't find any documentation either specifically about this, or that as I understand it, would allow me to achieve this.
If I use {{ product.weight | weight_in_units }} in the partial that is pulled through to show my products on the collection page, it shows 0.0lbs, as I assume it's trying to pull the weight on the collection page itself, which of course doesn't exists and is therefore 0. What I'm trying to achieve is showing each products weight under the product in the collection.
Is there any assistance you can provide, or even point me in the direction of the correct documentation?
Any help would be greatly appreciated.
Hi,
Thanks for the info so far. I can get the weight displaying on all products in kg.
However, I have a slightly more complex requirement.
I would like to display product weight in grams, and ONLY when a product weight has been added (this could be done by adding some code saying if the product weight is zero, don't display?)
Any help would be greatly appreciated - thanks in advance!
You can change your unit from admin product to gram and then add this code in snippet->product-grid.liquid file at bottom:
{% if product.variants.first.weight > 0%}
{ { product.variants.first.weight | weight_with_unit }}
{% endif %}
Hello and thanks for your message.
Unfortunately this didn't help.
Firstly, I don't have a file named product-grid.liquid
Secondly I want the weight to be shown next to the product name on the collection page.
For example Product Name (250g)
Cheers,
Wayne
The solution I found to this contained two parts:
Adding in a New Meta Field using an app, and then pulling that info through in the correct place.
Your template name may well be different, for me the Collection Card info is held in a template called: partial--product.liquid
Add a new meta tag with
Namespace: global
Key: display_weight (or any identifier of your choice)
Value: [Enter Weight & Measurement here]
I then used the following code in my desired place to pull through that information:
<span class="collection_weight">{{ product.metafields['global']['display_weight'] }} </span>
Style .collection_weight however you see fit. This method lets you control when it appears (if it's blank, it no content appears), and it's measurement. As the meta field is a string you just type in grams instead of kg. The drawback is that this isn't dynamic, but I wouldn't think you would/should be changing the weight of the same product constantly.
My result:
You can try this code on collection page grid.
Snippet->product-grid file
{% if product.variants.first.weight > 0%}
{ { product.variants.first.weight | weight_with_unit }}
{% endif %}
User | Count |
---|---|
418 | |
165 | |
94 | |
90 | |
88 |