Displaying product variant metafields on Expanse theme 2.0.1

markatia
New Member
3 0 0

I am currently having an issue checking and displaying product variant metafield with the below syntax. Any help would be great!

 

{% if variant.metafields.variant.shade != blank %}
<p>Hex: {{ variant.metafields.variant.shade }}</p>
{% endif %}

 

 

0 Likes

Hi @markatia,

Please change the code:

{% for variant in product.variants %}
{% if variant.metafields.variant.shade != blank %}
<p>Hex: {{ variant.metafields.variant.shade }}</p>
{% endif %}
{% endfor %}

You need to display product variant metafields.

Hope it is clear to you.

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

LitExtension - #1 Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!
0 Likes
markatia
New Member
3 0 0
Hi,

Thanks for your help.

I had to loop through the variant like so product.variants[forloop.index0].metafields.variant.shade to get the right metafields value.
0 Likes

You can also check with variant.title. Ex:

{% for variant in product.variants %}
{% if variant.metafields.variant.shade != blank and variant.title == 'Red' %}
<p>Hex: {{ variant.metafields.variant.shade }}</p>
{% endif %}
{% endfor %}

With this you can filter out all metafields of variant.

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

LitExtension - #1 Shopping Cart Migration Expert
If our answer is helpful then please accept as solution!
Are you looking for a solution to migrate to Shopify? Contact us for further assistance.
Try our FREE DEMO now!
0 Likes