use Apply Metafields Changehook
Returns a function to mutate the metafields
property of the checkout.
Anchor to useApplyMetafieldsChangeuse Apply Metafields Change()
UseApplyMetafieldsChangeGeneratedType
Returns a function to mutate the `metafields` property of the checkout.
(change: MetafieldChange) => Promise<MetafieldChangeResult>
export function useApplyMetafieldsChange<
Target extends RenderExtensionTarget = RenderExtensionTarget,
>(): (change: MetafieldChange) => Promise<MetafieldChangeResult> {
const api = useApi<Target>();
if ('applyMetafieldChange' in api) {
return api.applyMetafieldChange;
}
throw new ExtensionHasNoMethodError(
'applyMetafieldChange',
api.extension.target,
);
}
MetafieldChange
MetafieldRemoveChange | MetafieldUpdateChange | MetafieldRemoveCartChange | MetafieldUpdateCartChange
MetafieldRemoveChange
Removes a metafield.
- type
The type of the `MetafieldRemoveChange` API.
"removeMetafield"
- key
The name of the metafield to remove.
string
- namespace
The namespace of the metafield to remove.
string
export interface MetafieldRemoveChange {
/**
* The type of the `MetafieldRemoveChange` API.
*/
type: 'removeMetafield';
/**
* The name of the metafield to remove.
*/
key: string;
/**
* The namespace of the metafield to remove.
*/
namespace: string;
}
Metafield
Metadata associated with the checkout.
- key
The name of the metafield. It must be between 3 and 30 characters in length (inclusive).
string
- namespace
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).
string
- value
The information to be stored as metadata.
string | number
- valueType
The metafield’s information type.
"string" | "integer" | "json_string"
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';
}
MetafieldUpdateChange
Updates a metafield. If a metafield with the provided key and namespace does not already exist, it gets created.
- type
The type of the `MetafieldUpdateChange` API.
"updateMetafield"
- key
The name of the metafield to update.
string
- namespace
The namespace of the metafield to add.
string
- value
The new information to store in the metafield.
string | number
- valueType
The metafield’s information type.
"string" | "integer" | "json_string"
export interface MetafieldUpdateChange {
/**
* The type of the `MetafieldUpdateChange` API.
*/
type: 'updateMetafield';
/** The name of the metafield to update. */
key: string;
/** The namespace of the metafield to add. */
namespace: string;
/** The new information to store in the metafield. */
value: string | number;
/**
* The metafield’s information type.
*/
valueType: 'integer' | 'string' | 'json_string';
}
MetafieldRemoveCartChange
Removes a cart metafield.
- type
The type of the `MetafieldRemoveChange` API.
"removeCartMetafield"
- key
The name of the metafield to remove.
string
- namespace
The namespace of the metafield to remove.
string
export interface MetafieldRemoveCartChange {
/**
* The type of the `MetafieldRemoveChange` API.
*/
type: 'removeCartMetafield';
/**
* The name of the metafield to remove.
*/
key: string;
/**
* The namespace of the metafield to remove.
*/
namespace: string;
}
CartMetafield
Represents a custom metadata attached to a resource.
- key
The key name of a metafield.
string
- namespace
The namespace for a metafield.
string
- value
The value of a metafield.
string
- type
The metafield's type name.
string
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;
}
MetafieldUpdateCartChange
Updates a cart metafield. If a metafield with the provided key and namespace does not already exist, it gets created.
- type
The type of the `MetafieldUpdateChange` API.
"updateCartMetafield"
- metafield
{ key: string; namespace: string; value: string; type: string; }
export interface MetafieldUpdateCartChange {
/**
* The type of the `MetafieldUpdateChange` API.
*/
type: 'updateCartMetafield';
metafield: {
/** The name of the metafield to update. */
key: string;
/** The namespace of the metafield to add. */
namespace: string;
/** The new information to store in the metafield. */
value: string;
/**
* The metafield’s information type.
* See the [`metafields documentation`](/docs/apps/custom-data/metafields/types) for a list of supported types.
*/
type: string;
};
}
MetafieldChangeResult
MetafieldChangeResultSuccess | MetafieldChangeResultError
MetafieldChangeResultSuccess
- type
The type of the `MetafieldChangeResultSuccess` API.
"success"
export interface MetafieldChangeResultSuccess {
/**
* The type of the `MetafieldChangeResultSuccess` API.
*/
type: 'success';
}
MetafieldChangeResultError
- type
The type of the `MetafieldChangeResultError` API.
"error"
- message
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.
string
export interface MetafieldChangeResultError {
/**
* The type of the `MetafieldChangeResultError` API.
*/
type: 'error';
/**
* 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.
*/
message: string;
}