Skip to main content

Cart Instructions

Instructions used to create the checkout.

The base API object provided to purchase extension targets.

Anchor to instructions
instructions
<>
required

The cart instructions used to create the checkout and possibly limit extension capabilities.

These instructions should be checked prior to performing any actions that may be affected by them.

For example, if you intend to add a discount code via the applyDiscountCodeChange method, check discounts.canUpdateDiscountCodes to ensure it's supported in this checkout.

Caution

As of version 2024-07, UI extension code must check for instructions before calling select APIs in case those APIs are not available. See the update guide for more information.

Anchor to useInstructions
useInstructions()

Returns the cart instructions used to create the checkout and possibly limit extension capabilities.

CartInstructions

attributes

Cart instructions related to cart attributes.

delivery

Cart instructions related to delivery.

discounts

Cart instructions related to discounts.

lines

Cart instructions related to cart lines.

metafields

Cart instructions related to metafields.

notes

Cart instructions related to notes.

Examples

Preact

import '@shopify/ui-extensions/preact';
import {render} from 'preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
if (
shopify.instructions.value.discounts
.canUpdateDiscountCodes
) {
return (
<s-button
onClick={() =>
shopify.applyDiscountCodeChange({
type: 'addDiscountCode',
code: 'FREE_SHIPPING',
})
}
>
Apply your loyalty discount
</s-button>
);
} else {
return (
<s-banner tone="warning">
Loyalty discounts are unavailable
</s-banner>
);
}
}
Was this page helpful?