Skip to main content

CheckoutApi

Requires access to protected customer data for some properties.

This API object is provided to extensions registered for the extension points that appear exclusively pre-purchase.

It extends the StandardApi and provides the write apis for the checkout data.

See the StandardApi examples for more information on how to use the API.

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 buyer is using an accelerated checkout method, such as Apple Pay, Google Pay, or Meta Pay.

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

Performs an update on the merchandise line items. It resolves when the new line items have been negotiated and results in an update to the value retrieved through the lines property.

Note

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

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

Performs an update on the discount codes. It resolves when the new discount codes have been negotiated and results in an update to the value retrieved through the discountCodes property.

Caution

See security considerations if your extension retrieves discount codes through a network call.

Note

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

(change: ) => Promise<>
required

Performs an update on the gift cards. It resolves when gift card change have been negotiated and results in an update to the value retrieved through the appliedGiftCards property.

Caution

See security considerations if your extension retrieves gift card codes through a network call.

Note

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

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

Performs an update on a piece of metadata attached to the cart or checkout:

  • If type is updateMetafield or removeMetafield, this mutation results in an update to the value retrieved through the metafields property. Metafields written by updateMetafield are carried over to the order.
  • If type is updateCartMetafield or removeCartMetafield, this mutation updates the metafield attached to the cart and results in an update to the value retrieved through the appMetafields property. Metafields written by updateCartMetafields are updated on the cart object only and are not carried over to the order.
Tip

Cart metafields are only available on carts created via the Storefront API version 2023-04 or later.

(change: ) => Promise<>
required

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

Note

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

Was this section helpful?
import {
render,
Checkbox,
useApplyAttributeChange,
} from '@shopify/checkout-ui-extensions-react';

// 1. Choose an extension point
render('Checkout::Dynamic::Render', () => (
<Extension />
));

function Extension() {
const applyAttributeChange =
useApplyAttributeChange();

// 2. Render a UI
return (
<Checkbox onChange={onCheckboxChange}>
I would like to receive a free gift with my
order
</Checkbox>
);

// 3. Call API methods to modify the checkout
async function onCheckboxChange(isChecked) {
const result = await applyAttributeChange({
key: 'requestedFreeGift',
type: 'updateAttribute',
value: isChecked ? 'yes' : 'no',
});
console.log(
'applyAttributeChange result',
result,
);
}
}