Create variant metafield
mutation { metafieldsSet(metafields: [{ ownerId: "gid://shopify/ProductVariant/123", namespace: "custom", key: "color_hex", value: "#FF0000", type: "single_line_text_field" }]) { metafields { id } } }
Query metafields
{ productVariant(id: "gid://shopify/ProductVariant/123") { metafield(namespace: "custom", key: "color_hex") { value } } }
Dynamic Sources
Shopify 2.0 feature — theme editor binds metafield to display slots (like Product page description). No code needed for merchant.
Use cases
- Color hex for swatches
- Custom care instructions per variant
- Print spec per variant (DPI, format)
- Cost basis for margin tracking
Frequently asked questions
How to set variant metafield via API?
metafieldsSet mutation with ownerId = variant GID, namespace, key, value, type.
Query variant metafield in Liquid?
{{ variant.metafields.custom.color_hex }}.
Dynamic Sources — what is it?
Shopify 2.0 theme editor feature. Bind metafield to display slot without code.
Best metafield types for options?
single_line_text (color hex), boolean (flag), file_reference (image), integer (count).
Bulk create metafields?
metafieldsSet accepts array of up to 25 metafields per call.
Read metafield from Storefront API?
Query metafields on variant. Or expose via @metafield directive.
Metafield vs option — when?
Metafield: merchant-defined structured data. Option: customer-facing choice.
Metafield definition — required?
For Dynamic Sources yes. Definition adds validation + editor UI.
Related reading
Try it free on Shopify
Print It My Way's permanent Free plan includes live preview, custom options, and Cart Transform pricing.
Install Print It My Way