Preload Shopify metafields onto products and variants so you can read them from transforms, intents, and views.
Declare additional Shopify metafields you want Swish to fetch alongside product and variant data. Once preloaded, metafield values are available on product.metafields and variant.metafields (keyed by namespace, then by key) and are passed to transforms, intents, and view sections.
Each entry is a namespace.key string. Metafields are loaded with the rest of the product data, so they are available the moment the product is rendered.
Metafields are exposed as a nested record keyed by namespace, then by key. Any namespace you declared in metafields.product or metafields.productVariant is always present (as {} when no values are set), so you only need optional chaining at the namespace level for namespaces you didn’t declare.
const value = product.metafields.custom?.material;
For namespaces that contain special characters (for example, app-reserved namespaces like $app:swish), use bracket access:
const value = product.metafields["$app:swish"]?.setup;
Values are always strings. Cast or parse them as needed for non-string types (numbers, JSON, references).
Only declare the metafields you actually use. Each entry adds a field to the
Shopify Storefront API query, which counts against your storefront cost
budget.