Variant metafields are invalid - how do I fix?

Variant metafields are invalid - how do I fix?

jmpt16
New Member
4 0 0

So I have a variant metafield called "material".

 

pic1.png

But whenever I try to put it in a page, it doesn't show up!

pic2.png

And when I try to force it to show up, it says it's invalid.

pic3.png

How do I fix this?

Replies 6 (6)

LitExtension
Shopify Partner
4901 1004 1176

Hi @jmpt16,

Because you create Metafield Variants, so you just call it out with code, you can't import it at Customize. 

You need to add "for" variant for it. Refer

{%- for variant in product.variants -%} 
          {{variant.metafields.my_fields.material }} 
{%- endfor -%}

Hope it is clear to you.

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
Contact us:
- Email: contact@litextension.com
jmpt16
New Member
4 0 0

Still doesn't work that way, Shopify says it's invalid.

LitExtension
Shopify Partner
4901 1004 1176

Hi @jmpt16,

Can you send me the screenshot where you add the code. I will check it.

Because it needs to be added at main-product.liquid file.

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
Contact us:
- Email: contact@litextension.com
jmpt16
New Member
4 0 0

Oh, I didn't know I had to add it to main-product.liquid. 
Well, now it shows up, but it shows every variant's metafield value for every dropdown.

 

p2.png

(yes, those are the values i gave to the products. Heck, there should be more but I didn't bother filling them all out just yet)

Here's a code screenshot:

p1.png

How do I get only this variant's metafield value and only in the first dropdown?

(P.S: I'm gonna need to add another variant metafield for the 3rd dropdown as well)

LitExtension
Shopify Partner
4901 1004 1176

Hi @jmpt16,

Please change code:

{{ product.selected_or_first_available_variant.metafields.my_fields.material }}

Hope it helps!

LitExtension - Shopping Cart Migration Expert
Check out our Shopify migration app to migrate your online store to Shopify
Contact us:
- Email: contact@litextension.com
DabsDesign
Shopify Partner
49 1 11

Works perfect, thanks man!

DABS Design - Sua Agência Shopify no Brasil. Somos especialistas em Shopify e Shopify Plus, oferecendo consultoria, suporte, criação, integração de Apps e desenvolvimento para sua loja virtual. Conte com uma agência Shopify Expert Partner para potencializar o seu negócio! Entre em contato conosco. Transforme sua loja com os especialistas em Shopify no Brasil!