Attributes API
Use the Attributes API to read and write custom key-value pairs attached to the cart that persist through checkout. These key-value pairs are a lightweight way to keep buyer choices, operational details, and feature flags on the cart so that extensions and merchant workflows can all access the same values.
Attributes are shared across all extensions and the storefront. Any extension can read or overwrite attributes set by another.
To store custom data, Shopify recommends that you use the Metafields API to write cart metafields.
Metafields are safer than cart attributes as they support edit and view permissions and app-reserved namespaces to prevent other apps from reading and writing data.
To store custom data, Shopify recommends that you use the Metafields API to write cart metafields.
Metafields are safer than cart attributes as they support edit and view permissions and app-reserved namespaces to prevent other apps from reading and writing data.
Anchor to Use casesUse cases
- Track buyer preferences: Store buyers' custom selections like gift wrapping or personalization options as key-value pairs on the cart.
- Conditionally display UI: Show or hide features based on the cart's current attributes.
- Store operational data: Capture purchase order numbers, reference codes, or other operational data that the merchant needs for accounting or shipping.
Supported targets
- purchase.
address-autocomplete. format-suggestion - purchase.
address-autocomplete. suggest - purchase.
checkout. actions. render-before - purchase.
checkout. block. render - purchase.
checkout. cart-line-item. render-after - purchase.
checkout. cart-line-list. render-after - purchase.
checkout. chat. render - purchase.
checkout. contact. render-after - purchase.
checkout. delivery-address. render-after - purchase.
checkout. delivery-address. render-before - purchase.
checkout. footer. render-after - purchase.
checkout. header. render-after - purchase.
checkout. payment-method-list. render-after - purchase.
checkout. payment-method-list. render-before - purchase.
checkout. pickup-location-list. render-after - purchase.
checkout. pickup-location-list. render-before - purchase.
checkout. pickup-location-option-item. render-after - purchase.
checkout. pickup-point-list. render-after - purchase.
checkout. pickup-point-list. render-before - purchase.
checkout. reductions. render-after - purchase.
checkout. reductions. render-before - purchase.
checkout. shipping-option-item. details. render - purchase.
checkout. shipping-option-item. render-after - purchase.
checkout. shipping-option-list. render-after - purchase.
checkout. shipping-option-list. render-before - purchase.
thank-you. announcement. render - purchase.
thank-you. block. render - purchase.
thank-you. cart-line-item. render-after - purchase.
thank-you. cart-line-list. render-after - purchase.
thank-you. chat. render - purchase.
thank-you. customer-information. render-after - purchase.
thank-you. footer. render-after - purchase.
thank-you. header. render-after
Supported targets
- purchase.
address-autocomplete. format-suggestion - purchase.
address-autocomplete. suggest - purchase.
checkout. actions. render-before - purchase.
checkout. block. render - purchase.
checkout. cart-line-item. render-after - purchase.
checkout. cart-line-list. render-after - purchase.
checkout. chat. render - purchase.
checkout. contact. render-after - purchase.
checkout. delivery-address. render-after - purchase.
checkout. delivery-address. render-before - purchase.
checkout. footer. render-after - purchase.
checkout. header. render-after - purchase.
checkout. payment-method-list. render-after - purchase.
checkout. payment-method-list. render-before - purchase.
checkout. pickup-location-list. render-after - purchase.
checkout. pickup-location-list. render-before - purchase.
checkout. pickup-location-option-item. render-after - purchase.
checkout. pickup-point-list. render-after - purchase.
checkout. pickup-point-list. render-before - purchase.
checkout. reductions. render-after - purchase.
checkout. reductions. render-before - purchase.
checkout. shipping-option-item. details. render - purchase.
checkout. shipping-option-item. render-after - purchase.
checkout. shipping-option-list. render-after - purchase.
checkout. shipping-option-list. render-before - purchase.
thank-you. announcement. render - purchase.
thank-you. block. render - purchase.
thank-you. cart-line-item. render-after - purchase.
thank-you. cart-line-list. render-after - purchase.
thank-you. chat. render - purchase.
thank-you. customer-information. render-after - purchase.
thank-you. footer. render-after - purchase.
thank-you. header. render-after
Anchor to PropertiesProperties
The shopify global object provides attribute data for the current checkout. Access the following properties on shopify to read custom key-value pairs attached to the cart. Available to purchase extension targets.
- Anchor to attributesattributesattributesSubscribableSignalLike<Attribute[]>SubscribableSignalLike<Attribute[]>requiredrequired
The custom key-value attributes attached to the cart or checkout. These are set by the buyer or by an extension using
. The list is empty if no attributes have been added.
SubscribableSignalLike
Represents a reactive signal interface that provides both immediate value access and subscription-based updates. Enables real-time synchronization with changing data through the observer pattern. This interface extends `ReadonlySignalLike` with deprecated fields that are still supported for backwards compatibility.
- current
The current value of the signal. Equivalent to `.value`, accessing this property subscribes to changes when used in a reactive context.
T - destroy
Cleans up the subscription and releases any resources held by this signal. After calling `destroy()`, the signal stops receiving updates from the main thread.
() => Promise<void> - subscribe
Subscribes to value changes and calls the provided function whenever the value updates. Returns an unsubscribe function to clean up the subscription. Use to automatically react to changes in the signal's value.
(fn: (value: T) => void) => () => void - value
The current value of the signal. This property provides immediate access to the current value without requiring subscription setup. Use for one-time value checks or initial setup.
T
Attribute
- key
The identifier for the attribute. Each key must be unique within the set of attributes on the cart or checkout. If you call `applyAttributeChange()` with a key that already exists, then the existing value is replaced.
string - value
The value associated with the attribute key. This is a freeform string that can store any information the buyer or app provides. Attribute values are always strings. To store structured data, serialize it to JSON and parse it when reading.
string
Anchor to MethodsMethods
The shopify global object provides methods to modify attribute data. Access the following methods on shopify to apply attribute changes. Available to purchase.checkout extension targets.
- Anchor to applyAttributeChangeapplyAttributeChangeapplyAttributeChange(change: AttributeChange) => Promise<AttributeChangeResult>(change: AttributeChange) => Promise<AttributeChangeResult>requiredrequired
Updates or removes an attribute on the cart and checkout. On success, the
attributesproperty updates to reflect the change.NoteThis method returns an error if the cart instruction
is false, or the buyer is using an accelerated checkout method, such as Apple Pay or Google Pay.Note:This method returns an error if the cart instruction
is false, or the buyer is using an accelerated checkout method, such as Apple Pay or Google Pay.Note: This method returns an error if the <a href="/docs/api/checkout-ui-extensions/2025-10/apis/cart-instructions#properties-propertydetail-instructions">cart instruction</a> <code><span class="PreventFireFoxApplyingGapToWBR">attributes.can<wbr/>Update<wbr/>Attributes</span></code> is false, or the buyer is using an accelerated checkout method, such as Apple Pay or Google Pay.
AttributeChange
The input for `applyAttributeChange()`. Pass either an `AttributeUpdateChange` (with `type: 'updateAttribute'`) to set the attribute or an `AttributeRemoveChange` (with `type: 'removeAttribute'`) to delete it.
AttributeUpdateChange | AttributeRemoveChangeAttributeUpdateChange
Updates an attribute on the cart and checkout. If an attribute with the provided key doesn't already exist, then it gets created.
- key
The key of the attribute to add or update. If an attribute with this key already exists, then its value is replaced.
string - type
Identifies this as an attribute update or creation. Set this when creating a change to add or replace an attribute value.
'updateAttribute' - value
The new value for the attribute.
string
AttributeRemoveChange
Removes an attribute from the checkout. Pass this to `applyAttributeChange()` to delete an attribute by key. If the key doesn't exist, then the change has no effect.
- key
The key of the attribute to remove.
string - type
Identifies this as an attribute removal. Set this when creating a change to delete an attribute by key.
'removeAttribute'
AttributeChangeResult
The result of calling `applyAttributeChange()`. Use the `type` property to determine whether the change succeeded or failed.
AttributeChangeResultSuccess | AttributeChangeResultErrorAttributeChangeResultSuccess
The result of a successful attribute change. The `type` property is `'success'`.
- type
Indicates that the attribute change was applied successfully.
'success'
AttributeChangeResultError
The result of a failed attribute change. Check the `message` property for details about what went wrong.
- message
A message that explains the error. This message is useful for debugging. It isn't localized and shouldn't be displayed to the buyer.
string - type
Indicates that the attribute change couldn't be applied. Check the `message` property for details.
'error'
Anchor to Available Preact hooksAvailable Preact hooks
The following Preact hooks provide a convenience wrapper that makes it easier to perform common tasks without writing your own logic.
The hook returns an array of attribute values for the specified keys. Use this hook when you need to read the values of only some of the cart's attributes and you know the values' keys.
Anchor to useAttributeValues-parametersParameters
- Anchor to keyskeyskeysstring[]string[]requiredrequired
An array of attribute keys.
Anchor to Best practicesBest practices
- Check
canUpdateAttributesbefore rendering mutation UI: Use theinstructionsproperty on the globalshopifyobject to verifyinstructions.attributes.canUpdateAttributesbefore showing attribute controls. If it'sfalse, hide the feature entirely. - Use descriptive, namespaced keys: Choose clear, unique attribute keys to avoid collisions with other extensions. For example, use
myApp_giftWraprather thangift.
Anchor to LimitationsLimitations
- Attribute changes aren't available when the buyer uses an accelerated checkout method such as Apple Pay or Google Pay.