If you want to add validation rules to an existing set of Metafields, then you can migrate your Metafields to a definition. When you create a custom definition for existing sets of Metafields, the validation rules that you specify prevent you or your apps from adding invalid values.
You migrate your Metafields by creating a custom definition for a set of Metafields with a particular namespace and key. You can migrate Metafields to most content types, except for file, reference, and true or false. For more information about creating custom definitions, refer to the following:
You can only add definitions for sets of metafields that have a namespace and key with the correct format. If your namespace and key contains special characters, then you can't migrate that set of Metafields to a definition.
Create a definition for sets of Metafields that don't yet have a definition
- From your Shopify admin, go to Settings > Metafields.
- Select the part of your store that you want to add a metafield definition for. For example, Products.
- Click Metafields without a definition, and then click Add definition next to the namespace and key that you want to add a definition for.
- Review the Sample metafield to determine the correct type and validation rules for the namespace and key. To display additional sample values, click View more.
- Enter the following information for your Metafield definition:
- In the Name field, enter a name for your definition.
- Optional: In the Description field, enter a description for your Metafield.
- Click Select content type, and then select the content type that best matches your Metafield values from the list.
- Configure the content type and validation information by doing the following:
- If the content type has additional configuration options, then select the correct option for your Metafield. For example, type of measurement.
- In the Validation section, configure the Additional rules for your definition.
- Click Save.
- Review the validation results, and then click Save and continue.
If any Metafield values don’t match your new definition, then you need to fix your Metafield values. After you save your definition, you're automatically redirected to the bulk editor to review and fix any validation errors.
Edit Metafields without a definition
Third-party Metafields from an app can be migrated into your Shopify admin, but they are hidden. You can edit these Metafields from the resource page that they appear on.
- From your Shopify admin, go to the resource that has the migrated Metafields.
- Scroll down to the Metafields section.
- Click Show all.
- Click the Metafield line for the definition you want to edit, and then add the value.
- Click Save.
If you don't see the Metafields section on your resource page, then go to Settings > Metafields and make sure at least one Metafield definition exists. You can't see Metafields in your resource without having at least one Metafield definition created.
Next steps after adding metafield definitions
After you add definitions for your Metafields, you can do the following: