Shopify themes, liquid, logos, and UX
Hello, I would like to know how to make it so that when I choose a variant it shows me the weight only of the variant that I have chosen. Now all the weights of all the variants are shown. Right now i used this to call <p>Weight: {% for variant in product.variants %}{{variant.weight | weight_with_unit }}{% endfor %}</p>
And this is the result.
https://fantasticjewelrynyc.com/products/cuban-link-chain-14k-gold
To display the weight of the selected variant only, you can modify the Liquid code in your product template. Here's an example of how you can achieve this:
Access the theme editor: Go to your Shopify admin dashboard and navigate to "Online Store" -> "Themes". Find your current theme and click on the "Actions" dropdown, then select "Edit code".
Locate the product template: In the theme editor, look for the file that controls the product template. This is typically named product.liquid
or similar. Open it in the code editor.
Find the variant selection code: Within the product template code, search for the code that handles the variant selection. This code is usually responsible for displaying variant options and updating the selected variant.
Add a conditional statement: After the variant selection code, add a conditional statement to check if a variant is selected. You can use the product.selected_or_first_available_variant
object to access the currently selected variant. Here's an example:
{% if product.selected_or_first_available_variant %}
<p>Weight: {{ product.selected_or_first_available_variant.weight | weight_with_unit }}</p>
{% endif %}
weight_with_unit
filter.Hello, thanks for your help, I did what you indicated, the weight of the variation is indeed shown, however, when I choose another variation the weight does not change, if I reload the page the new weight is shown but I would like you to tell me what I should make it so that the weight is changed automatically when you choose a new variation.
It looks like you have this working on your store now, could I ask how you did this please?
Hi were you able to get an answer on how this was done ? I have been trying to find a solution and would love some help.
Hello, can i show the shipping cost according to variant weight? and put them on the product page, can you please help me with this?
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024