Skip to main content

Using metafields for custom data in checkout

Metafields are key-value pairs that you can use to store custom data on a Shopify resource. You can use metafields to store data that is specific to your checkout UI extension, such as the extension's configuration or the buyer's consent.

To access metafields in your checkout UI extension, use the Metafields API.

For a full tutorial on using metafields read and write custom data in your checkout UI extension, see Display custom data at checkout.


Anchor to Configuring metafieldsConfiguring metafields

To use metafields in your checkout UI extension, you need to configure them in your extension's .toml configuration file file.

To define a metafield that's available to your extension wherever it's rendered in the checkout, use theextensions.metafields property.

To define a metafield that your extension can access only from a specific extension target, use the extensions.targeting.metafields property.

The following example snippet shows two metafields defined using these properties:

shopify.extension.toml snippet

# Define a metafield your extension can access from anywhere in checkout
[[extensions.metafields]]
namespace = "my-namespace"
key = "my-key-1"

[[extensions.targeting]]
target = "purchase.checkout.actions.render-before"
module = "./Actions.jsx"

# Define a metafield your extension can access only from the above target
[[extensions.targeting.metafields]]
namespace = "my-namespace"
key = "my-target-key"

Anchor to App owned metafieldsApp owned metafields

When your app needs to control the data and visibility of the metafield, you can use app owned metafields. Using an app-owned metafield prevents other apps or merchants from accessing or modifying the data stored in the metafield.

Your extension can only access app-owned metafields that belong to its parent app.

The following example snippet shows a definition for an app-owned metafield:

shopify.extension.toml snippet

# app owned metafield
[[extensions.metafields]]
namespace = "$app:my-app-owned-namespace"
key = "my-key-3"

Anchor to Supported resource metafield typesSupported resource metafield types

The following resource metafield types are supported:

ResourceDescription
cartThe cart associated with the current checkout.
companyThe company for B2B checkouts.
companyLocationThe company's location for B2B checkouts.
customerThe customer account that is interacting with the current checkout.
productThe products that the buyer intends to purchase.
shopThe shop that is associated with the current checkout.
shopUserThe Shop app user that is associated with the current checkout if there is one.
variantThe product variants that the customer intends to purchase.

Was this page helpful?