Skip to main content

Metafield-linked product options

Learn about how to link metafields to product options in the new product model.


Anchor to Why we've made these changesWhy we've made these changes

The updated Shopify product taxonomy is an open-source comprehensive, global standard for product classification. It's a universal language that empowers merchants to categorize their products. Spanning 22 essential verticals, our taxonomy encompasses categories, attributes, and values, all thoughtfully integrated within Shopify and numerous marketplaces.

By using metaobjects to model each attribute's values (as metaobject entries), we ensure reusability and shop-specific customization. To connect metaobjects to any resource in Shopify, we use metafields (of type list.metaobject_reference). Then, we introduced the ability to connect these metaobjects such that merchants can create variants for each attribute value.


Anchor to Linking product options to metafieldsLinking product options to metafields

Any metafield definition that meets the following criteria can also be used to create variants:

  • Owner type is Product.

  • Type is list.metaobject_reference.

  • Validation options do not include list.min or list.max.

  • Access controls are set to merchant writable.

    The metaobject referenced by the metafield can be either a standard, such as shopify--color-pattern, or a custom metaobject with any set of fields. The only requirement is that the metaobject definition must be merchant writable.

    Follow these steps to create variants powered by metafield-linked product options:

Anchor to Step 1: Create metaobject entries for your attributesStep 1: Create metaobject entries for your attributes

POST https://{shop}.myshopify.com/api/{api_version}/graphql.json

Create metaobject entries that will represent your attribute values. These entries can either belong to standard definitions or custom metaobjects with the requisite access controls.

GraphQL mutation

mutation MetaobjectCreate($metaobject: MetaobjectCreateInput!) {
metaobjectCreate(metaobject: $metaobject) {
metaobject {
id
displayName
fields {
key
value
}
}
userErrors {
field
message
}
}
}

Variables

{
"metaobject": {
"type": "shopify--color-pattern",
"fields": [
{
"key": "color_taxonomy_reference",
"value": "[\"gid://shopify/TaxonomyValue/3\", \"gid://shopify/TaxonomyValue/10\"]"
},
{
"key": "pattern_taxonomy_reference",
"value": "gid://shopify/TaxonomyValue/2874"
},
{
"key": "label",
"value": "Orange/Blue"
}
]
}
}

Anchor to Step 2: Create or update products with linked optionsStep 2: Create or update products with linked options

Once you have your metaobject entries, you can create or update products using these linked options. Here's an example using the productSet mutation:

GraphQL mutation

mutation productSet {
productSet(synchronous: true, input: {
title: "T-Shirt"
category: "gid://shopify/TaxonomyCategory/aa-1-13-7"
productOptions: [
{
name: "Size",
values: [
{ name: "Small"},
{ name: "Medium"},
]
},
{
name: "Color",
linkedMetafield: {
namespace: "shopify",
key: "color-pattern",
}
}
],
variants: [
{
position: 0
optionValues: [
{ optionName: "Size", name: "Small" },
{ optionName: "Color", linkedMetafieldValue: "gid://shopify/Metaobject/70095274073" }
]
},
{
position: 1
optionValues: [
{ optionName: "Size", name: "Medium" },
{ optionName: "Color", linkedMetafieldValue: "gid://shopify/Metaobject/70095274073" }
]
}
]
}) {
userErrors { message }
product {
id
}
}
}

Was this page helpful?