Solved

Can't access my variant metafields

TheThisThat
Shopify Partner
61 3 17

I am mystified. I have added a metafield to all my product variants called fabric_content.

 

metafieldmetafield

 

 

 

 

 

 

 

I can see my variant when I run this code.

 

 

{%assign current_variant = product.selected_or_first_available_variant%}
{{current_variant.option2}}

 

 

 

But when I try to view the actual metafield attached to that variant nothing shows up.

 

 

{{current_variant.option2.metafields.description.fabric_content}}

 

 

It works find if I try to access metafields on a product. Just not on the product variant. 

I've tried changing the metafield name and still nothing. 

Any suggestions of what I could be doing wrong? 

a little of this and a little of that
Accepted Solution (1)

Jason
Shopify Expert
11190 225 2283

This is an accepted solution.

In your code you are assigning a variant to this var:

current_variant

and then you are referencing the second option in that variant. 

current_variant.option2


More info on option2 in here:
https://shopify.dev/api/liquid/objects/variant

But metafields are not attached to options, like option2. They are attached to objects like products or variants. 

So more like this:

{{ current_variant.metafields.description.fabric_content }}

 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★

View solution in original post

Replies 3 (3)

Jason
Shopify Expert
11190 225 2283

This is an accepted solution.

In your code you are assigning a variant to this var:

current_variant

and then you are referencing the second option in that variant. 

current_variant.option2


More info on option2 in here:
https://shopify.dev/api/liquid/objects/variant

But metafields are not attached to options, like option2. They are attached to objects like products or variants. 

So more like this:

{{ current_variant.metafields.description.fabric_content }}

 

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
Its_Cherry
New Member
9 0 0

{collections(query:name:Test){edges{node{id,title}}}}

"errors":[{"message":"Parse error on \":\" (COLON) at [1, 24]","locations":[{"line":1,"column":24}]}]

 

can you help please me?

AvidBrio
Shopify Expert
295 17 29

@Jason   Thanks for the answers.

I am working on shopify product variants  meta field.   
https://community.shopify.com/c/shopify-design/how-to-map-the-variants-with-shopify-product-meta-fil...  here is my Question i hope you will answer it.

If you find our comment helpful, hit the like button and accept it as a solution.
Want us to implement custom changes in your store? Contact us
Email me directly - jim@avidbrio.com