The Variant Product Does Not Change The weight When Selected

fantasticnyc
Visitor
2 0 0

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.

Captura de Pantalla 2023-05-08 a la(s) 2.11.11 p. m..png

https://fantasticjewelrynyc.com/products/cuban-link-chain-14k-gold

Replies 4 (4)

NomtechSolution
Astronaut
1245 113 147

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:

  1. 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".

  2. 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.

  3. 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.

  4. 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 %}

 

 

  • In this example, the conditional statement checks if a variant is selected. If a variant is selected, it displays the weight of that variant using the weight_with_unit filter.
fantasticnyc
Visitor
2 0 0

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.

Captura de Pantalla 2023-05-09 a la(s) 11.11.40 a. m..png

John_Benson
Shopify Partner
2 0 0

It looks like you have this working on your store now, could I ask how you did this please?

KelsoPremium
Visitor
2 0 0

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.