Display Product variant weight for option2 (not selected)

Kelly31
New Member
1 0 0

Hi team,

Ive searched everywhere for the answer to this question. Im wanting to display both variant weights on the product page and not just the selected variant.

{{ product.variants.first.weight | weight_with_unit }} works for the selected variant but how do I get the second one? Any ideas?

Thank you in advance!

Kelly

Reply 1 (1)
LitCommerce
Trailblazer
262 68 70

Hi @Kelly31,

You need to for variants:
{%- for variant in product.variants -%}
{{ variant.weight | weight_with_unit }}
{%- endfor -%}
It will show all variant and weight.
If you only want to show the 2nd variant, refer code:
{%- for variant in product.variants -%}
{%- if forloop.index == 2 -%}
{{ variant.weight | weight_with_unit }}
{% break %}
{%- endif -%}
{%- endfor -%}
Or
{{ product.variants[1].weight | weight_with_unit }}

Hope it helps!

If my answer can help you solve your issue, please mark it as a solution. Thank you and good luck.

LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool.
Effortlessly sell on biggest marketplaces like Amazon, Etsy, eBay, Facebook etc with bulk listing tool, real-time sync & smart order management. Use LitCommerce free for 1-year now!