Skip to main content

Attributes

The API for interacting with cart and checkout attributes.

The base API object provided to purchase extension targets.

Anchor to attributes
attributes
StatefulRemoteSubscribable<[] | undefined>
required

The custom attributes left by the customer to the merchant, either in their cart or during checkout.

The API object provided to purchase.checkout extension targets.

Anchor to applyAttributeChange
applyAttributeChange
(change: ) => Promise<>
required

Performs an update on an attribute attached to the cart and checkout. If successful, this mutation results in an update to the value retrieved through the attributes property.

Note

This method will return an error if the cart instruction attributes.canUpdateAttributes is false, or the buyer is using an accelerated checkout method, such as Apple Pay, Google Pay, or Meta Pay.

Anchor to useApplyAttributeChange
useApplyAttributeChange()

Returns a function to mutate the attributes property of the checkout.

(change: ) => Promise<>

Returns the proposed attributes applied to the checkout.

[] | undefined

Returns the values for the specified attributes applied to the checkout.

string[]
required

An array of attribute keys.

(string | undefined)[]
Examples
import {
Text,
reactExtension,
useAttributeValues,
} from '@shopify/ui-extensions-react/checkout';

export default reactExtension(
'purchase.checkout.block.render',
() => <Extension />,
);

function Extension() {
const [buyerSelectedFreeTShirt, tshirtSize] =
useAttributeValues([
'buyerSelectedFreeTShirt',
'tshirtSize',
]);

if (Boolean(buyerSelectedFreeTShirt) === true) {
return (
<Text>
You selected a free t-shirt, size:{' '}
{tshirtSize}
</Text>
);
}

return null;
}
Was this page helpful?