# useApplyMetafieldsChange Returns a function to mutate the `metafields` property of the checkout. ## ### UseApplyMetafieldsChangeGeneratedType Returns a function to mutate the `metafields` property of the checkout. #### Returns: (change: MetafieldChange) => Promise export function useApplyMetafieldsChange< Target extends RenderExtensionTarget = RenderExtensionTarget, >(): (change: MetafieldChange) => Promise { const api = useApi(); if ('applyMetafieldChange' in api) { return api.applyMetafieldChange; } throw new ExtensionHasNoMethodError( 'applyMetafieldChange', api.extension.target, ); } ### MetafieldRemoveChange Removes a metafield. ### type value: `"removeMetafield"` - Metafield: export interface Metafield { /** * The name of the metafield. It must be between 3 and 30 characters in * length (inclusive). */ key: string; /** * A container for a set of metafields. You need to define a custom * namespace for your metafields to distinguish them from the metafields * used by other apps. This must be between 2 and 20 characters in length (inclusive). */ namespace: string; /** * The information to be stored as metadata. */ value: string | number; /** The metafield’s information type. */ valueType: 'integer' | 'string' | 'json_string'; } The type of the `MetafieldRemoveChange` API. ### key value: `string` The name of the metafield to remove. ### namespace value: `string` The namespace of the metafield to remove. ### Metafield Metadata associated with the checkout. ### key value: `string` The name of the metafield. It must be between 3 and 30 characters in length (inclusive). ### namespace value: `string` A container for a set of metafields. You need to define a custom namespace for your metafields to distinguish them from the metafields used by other apps. This must be between 2 and 20 characters in length (inclusive). ### value value: `string | number` The information to be stored as metadata. ### valueType value: `"string" | "integer" | "json_string"` The metafield’s information type. ### MetafieldUpdateChange Updates a metafield. If a metafield with the provided key and namespace does not already exist, it gets created. ### type value: `"updateMetafield"` - Metafield: export interface Metafield { /** * The name of the metafield. It must be between 3 and 30 characters in * length (inclusive). */ key: string; /** * A container for a set of metafields. You need to define a custom * namespace for your metafields to distinguish them from the metafields * used by other apps. This must be between 2 and 20 characters in length (inclusive). */ namespace: string; /** * The information to be stored as metadata. */ value: string | number; /** The metafield’s information type. */ valueType: 'integer' | 'string' | 'json_string'; } The type of the `MetafieldUpdateChange` API. ### key value: `string` The name of the metafield to update. ### namespace value: `string` The namespace of the metafield to add. ### value value: `string | number` The new information to store in the metafield. ### valueType value: `"string" | "integer" | "json_string"` The metafield’s information type. ### MetafieldRemoveCartChange Removes a cart metafield. ### type value: `"removeCartMetafield"` - Metafield: export interface Metafield { /** * The name of the metafield. It must be between 3 and 30 characters in * length (inclusive). */ key: string; /** * A container for a set of metafields. You need to define a custom * namespace for your metafields to distinguish them from the metafields * used by other apps. This must be between 2 and 20 characters in length (inclusive). */ namespace: string; /** * The information to be stored as metadata. */ value: string | number; /** The metafield’s information type. */ valueType: 'integer' | 'string' | 'json_string'; } - CartMetafield: export interface CartMetafield { /** The key name of a metafield. */ key: string; /** The namespace for a metafield. */ namespace: string; /** The value of a metafield. */ value: string; /** The metafield's type name. */ type: string; } The type of the `MetafieldRemoveChange` API. ### key value: `string` The name of the metafield to remove. ### namespace value: `string` The namespace of the metafield to remove. ### CartMetafield Represents a custom metadata attached to a resource. ### key value: `string` The key name of a metafield. ### namespace value: `string` The namespace for a metafield. ### value value: `string` The value of a metafield. ### type value: `string` The metafield's type name. ### MetafieldUpdateCartChange Updates a cart metafield. If a metafield with the provided key and namespace does not already exist, it gets created. ### type value: `"updateCartMetafield"` - Metafield: export interface Metafield { /** * The name of the metafield. It must be between 3 and 30 characters in * length (inclusive). */ key: string; /** * A container for a set of metafields. You need to define a custom * namespace for your metafields to distinguish them from the metafields * used by other apps. This must be between 2 and 20 characters in length (inclusive). */ namespace: string; /** * The information to be stored as metadata. */ value: string | number; /** The metafield’s information type. */ valueType: 'integer' | 'string' | 'json_string'; } - CartMetafield: export interface CartMetafield { /** The key name of a metafield. */ key: string; /** The namespace for a metafield. */ namespace: string; /** The value of a metafield. */ value: string; /** The metafield's type name. */ type: string; } The type of the `MetafieldUpdateChange` API. ### metafield value: `{ key: string; namespace: string; value: string; type: string; }` ### MetafieldChangeResultSuccess ### type value: `"success"` The type of the `MetafieldChangeResultSuccess` API. ### MetafieldChangeResultError ### type value: `"error"` The type of the `MetafieldChangeResultError` API. ### message value: `string` A message that explains the error. This message is useful for debugging. It is **not** localized, and therefore should not be presented directly to the buyer. ## Related - [StandardApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/standardapi) - [CheckoutApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/checkoutapi) - [OrderStatusApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/orderstatusapi) - [CartLineItemApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/cartlineitemapi) - [PickupPointListApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/pickuppointlistapi) - [PickupLocationListApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/pickuplocationlistapi) - [ShippingOptionItemApi](https://shopify.dev/docs/api/checkout-ui-extensions/apis/shippingoptionitemapi) - [ExtensionTargets](https://shopify.dev/docs/api/checkout-ui-extensions/apis/extensiontargets)