Shopify Liquid Get Variant Object From Metafield

August 10th, 2022

When setting a metafield to a type “variant” you would be forgiven for thinking it would return a product object when accessed.

Unfortunately, this is Shopify so it returns a String GID.

It took me much longer than I would like to admit to figure this out. It was the reason I couldn’t access any of the variant variables.

To access the object replace:

card_product: product.metafields.namespace.real_variant


card_product: product.metafields.namespace.real_variant.value

Appending .value loads the object rather than returning shopify’s gid:// string.


Leave a Reply

Your email address will not be published. Required fields are marked *