Create a metafield definition in Shopify
A metafield is a labelled slot for one piece of data that Shopify has no built-in box for, such as a warranty length or care instructions. This tutorial creates a custom metafield definition for products, named Warranty months, and checks the warranty end dates it produces.
Written · Shopify admin, desktop steps · 6 minutes read
The worked example
| Resource | Products |
| Definition name | Warranty months |
| Namespace and key | custom.warranty_months |
| Type | Integer (under Number) |
| Example value | 24 |
Download the record: metafield-definition-record.csv (217 bytes).
A metafield record for the worked example definitions. Each row gives the definition name, its namespace and key, its type, and an example value.
1Open Metafields and metaobjects
From your Shopify admin, go to Settings then Metafields and metaobjects.
2Pick the part of the store
Select the part of your store that you want to add a metafield to, for example Products.
3Click Add definition
Click Add definition. If there is no standard metafield definition for the information you want to add, you create a custom definition.
4Enter the name
In the Name field, enter a name for your definition, for example Warranty months. If a matching standard definition appears as a suggestion below the field, you can click it to use the standard definition instead.
5Check the namespace and key
In the Namespace and key field, check the identifier generated from the name, for example custom.warranty_months. You can use a namespace to group similar metafields together, but each namespace and key must be unique.
6Select the type
Click Select type, then search for or select the type that best matches your metafield, for example Integer, which sits under the Number category. Add a description and any validation rules, such as a minimum and maximum value.
7Set the access
Optional: to allow custom storefronts to display values for this metafield, select Storefronts. By default, values for custom metafields are not accessible to custom storefronts.
8Save and add the value
Click Save. Then open a product and enter the value in the new field: 24 for the Summit Hoodie, 12 for the Trail Crew Tee and 6 for the Canvas Tote.
The arithmetic
| Product | Purchase date | Warranty ends |
|---|---|---|
| Summit Hoodie, 24 months | 11 November 2026 | 11 November 2028 |
| Trail Crew Tee, 12 months | 11 November 2026 | 11 November 2027 |
| Canvas Tote, 6 months | 11 November 2026 | 11 May 2027 |
A 24-month warranty bought on 11 November 2026 ends on 11 November 2028. A 12-month warranty ends on 11 November 2027, and a 6-month warranty ends on 11 May 2027.
Held at the counter
Each namespace and key must be unique. The namespace and key is the address themes and apps use to find the field. Two definitions cannot share one, so check the generated key before you save, and keep the naming consistent across your definitions.
Use the standard definition when Shopify suggests one. If a matching standard definition appears as a suggestion below the Name field, click it to use the standard definition instead of building a custom one. Standard definitions are the ones apps and themes already know how to read.
Values are not on custom storefronts by default. By default, values for custom metafields are not accessible to custom storefronts. If your storefront needs to read the value, select Storefronts in the definition before you save.
Sources
- Creating custom metafield definitions — Shopify's help pages: the create-definition steps, the namespace and key rule, the standard definition suggestion, and the Storefronts access default.