Ad

Access Image Metafield Inside Product.liquid In Shopify

- 1 answer

I am trying to access image metafield inside the product.liquid template in Shopify. This is the metafield on a image:

{
metafields: [
{
id: 11419631342244,
namespace: "tags",
key: "821753034",
value: "test",
value_type: "string",
description: this is a test,
owner_id: 124682934492,
created_at: "2019-12-23T18:20:58-05:00",
updated_at: "2019-12-23T18:20:58-05:00",
owner_resource: "product_image",
admin_graphql_api_id: "gid://shopify/Metafield/12312423535"
}
]
}

I tried accessing it under the {% for image in product.images %} When I access image.alt it returns the result, but when I access image.metafields.namespace['tags'] it returns nothing. I have tried different syntax. If anyone knows how I can access the metafields that will be great.

Ad

Answer

I Don't think you can access image meta fields to liquid.

But you can make use of product meta fields to achieve your goal.create product metafields with namespace like "image_metafields" pass image ID as metafield key and access it using liquid.

Metafiled Created through Metafield Guru Shopify APP

{% assign image_metafields = product.metafields.image_metafields %}

{% assign image_meta_id = "ik_" | append: image.id %}

<p> {{ image_metafields[image_meta_id] }} </p>
Ad
source: stackoverflow.com
Ad