How can I display the correct metafield for each product variant?

How can I display the correct metafield for each product variant?

jw8
Tourist
6 0 0

I have variant metafield that I'm trying to show on product page next to the variant option. Problem is that it currently shows all variant metafields on all variant options. I don't know how to only show the correct metafield on the correct variant.

 

Here's my code. 

 

{%- if product.type == 'Cyklar' -%}
  {% for variant in product.variants %}
     <div class="storlekstext">Passar längd: {{ variant.metafields.custom.langd.value.first }} - {{ variant.metafields.custom.langd.value.last }} cm</div>
  {% endfor %}
{%- endif -%}

 

Reply 1 (1)

gr_trading
Shopify Partner
2044 149 206

Hey @jw8 ,

 

Seems you have json type metafield because custom metafield named as variant.metafields.custom.langd but your metafield name is variant.metafields.custom.langd.value.first

 

It will be best you could share full structure of your metafield or metafield screenshot, so that we could provide you working solution.

For any custom development WhatsApp or connect at Email ID: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee