Cart InstructionsAPI
Instructions used to create the checkout.
Anchor to standardapiStandardApi
The base API object provided to purchase
extension targets.
- Anchor to instructionsinstructionsSubscribableSignalLike<CartInstructions>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
method, check
to ensure it's supported in this checkout.
CautionAs 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.
SubscribableSignalLike
Represents a read-only value managed on the main thread that an extension can subscribe to. Example: Checkout uses this to manage the state of an object and communicate state changes to extensions running in a sandboxed web worker. This interface is compatible with [Preact's ReadonlySignal](https://github.com/preactjs/signals/blob/a023a132a81bd4ba4a0bebb8cbbeffbd8c8bbafc/packages/core/src/index.ts#L700-L709). Some fields are deprecated but still supported for backwards compatibility. In version 2025-10, [`StatefulRemoteSubscribable`](https://github.com/Shopify/remote-dom/blob/03929aa8418a89d41d294005f219837582718df8/packages/async-subscription/src/types.ts#L17) was replaced with `ReadonlySignalLike`. Checkout will remove the old fields some time in the future.
- current
T
- destroy
() => Promise<void>
- subscribe
(fn: (value: T) => void) => () => void
- value
T
export interface SubscribableSignalLike<T> extends ReadonlySignalLike<T> {
/**
* @deprecated Use `.value` instead.
*/
readonly current: T;
/**
* @deprecated No longer needed. Use Preact Signal management instead.
*/
destroy(): Promise<void>;
}
CartInstructions
- attributes
Cart instructions related to cart attributes.
AttributesCartInstructions
- delivery
Cart instructions related to delivery.
DeliveryCartInstructions
- discounts
Cart instructions related to discounts.
DiscountsCartInstructions
- lines
Cart instructions related to cart lines.
CartLinesCartInstructions
- metafields
Cart instructions related to metafields.
MetafieldsCartInstructions
- notes
Cart instructions related to notes.
NotesCartInstructions
export interface CartInstructions {
/**
* Cart instructions related to cart attributes.
*/
attributes: AttributesCartInstructions;
/**
* Cart instructions related to delivery.
*/
delivery: DeliveryCartInstructions;
/**
* Cart instructions related to discounts.
*/
discounts: DiscountsCartInstructions;
/**
* Cart instructions related to cart lines.
*/
lines: CartLinesCartInstructions;
/**
* Cart instructions related to metafields.
*/
metafields: MetafieldsCartInstructions;
/**
* Cart instructions related to notes.
*/
notes: NotesCartInstructions;
}
AttributesCartInstructions
- canUpdateAttributes
Indicates whether or not cart attributes can be updated.
boolean
export interface AttributesCartInstructions {
/**
* Indicates whether or not cart attributes can be updated.
*/
canUpdateAttributes: boolean;
}
DeliveryCartInstructions
- canSelectCustomAddress
Indicates whether a buyer can select a custom address. When true, this implies extensions can update the delivery address.
boolean
export interface DeliveryCartInstructions {
/**
* Indicates whether a buyer can select a custom address.
*
* When true, this implies extensions can update the delivery address.
*/
canSelectCustomAddress: boolean;
}
DiscountsCartInstructions
- canUpdateDiscountCodes
Indicates whether or not discount codes can be updated.
boolean
export interface DiscountsCartInstructions {
/**
* Indicates whether or not discount codes can be updated.
*/
canUpdateDiscountCodes: boolean;
}
CartLinesCartInstructions
- canAddCartLine
Indicates whether or not new cart lines can be added.
boolean
- canRemoveCartLine
Indicates whether or not cart lines can be removed.
boolean
- canUpdateCartLine
Indicates whether or not cart lines can be updated.
boolean
export interface CartLinesCartInstructions {
/**
* Indicates whether or not new cart lines can be added.
*/
canAddCartLine: boolean;
/**
* Indicates whether or not cart lines can be removed.
*/
canRemoveCartLine: boolean;
/**
* Indicates whether or not cart lines can be updated.
*/
canUpdateCartLine: boolean;
}
MetafieldsCartInstructions
- canDeleteCartMetafield
Indicates whether or not cart metafields can be deleted.
boolean
- canSetCartMetafields
Indicates whether or not cart metafields can be added or updated.
boolean
export interface MetafieldsCartInstructions {
/**
* Indicates whether or not cart metafields can be added or updated.
*/
canSetCartMetafields: boolean;
/**
* Indicates whether or not cart metafields can be deleted.
*/
canDeleteCartMetafield: boolean;
}
NotesCartInstructions
- canUpdateNote
Indicates whether or not notes can be updated.
boolean
export interface NotesCartInstructions {
/**
* Indicates whether or not notes can be updated.
*/
canUpdateNote: boolean;
}
Anchor to useInstructionsuse Instructions()
Returns the cart instructions used to create the checkout and possibly limit extension capabilities.
- attributesAttributesCartInstructions
Cart instructions related to cart attributes.
- deliveryDeliveryCartInstructions
Cart instructions related to delivery.
- discountsDiscountsCartInstructions
Cart instructions related to discounts.
- linesCartLinesCartInstructions
Cart instructions related to cart lines.
- metafieldsMetafieldsCartInstructions
Cart instructions related to metafields.
- notesNotesCartInstructions
Cart instructions related to notes.
CartInstructions
CartInstructions
- attributes
Cart instructions related to cart attributes.
AttributesCartInstructions
- delivery
Cart instructions related to delivery.
DeliveryCartInstructions
- discounts
Cart instructions related to discounts.
DiscountsCartInstructions
- lines
Cart instructions related to cart lines.
CartLinesCartInstructions
- metafields
Cart instructions related to metafields.
MetafieldsCartInstructions
- notes
Cart instructions related to notes.
NotesCartInstructions
export interface CartInstructions {
/**
* Cart instructions related to cart attributes.
*/
attributes: AttributesCartInstructions;
/**
* Cart instructions related to delivery.
*/
delivery: DeliveryCartInstructions;
/**
* Cart instructions related to discounts.
*/
discounts: DiscountsCartInstructions;
/**
* Cart instructions related to cart lines.
*/
lines: CartLinesCartInstructions;
/**
* Cart instructions related to metafields.
*/
metafields: MetafieldsCartInstructions;
/**
* Cart instructions related to notes.
*/
notes: NotesCartInstructions;
}
AttributesCartInstructions
- canUpdateAttributes
Indicates whether or not cart attributes can be updated.
boolean
export interface AttributesCartInstructions {
/**
* Indicates whether or not cart attributes can be updated.
*/
canUpdateAttributes: boolean;
}
DeliveryCartInstructions
- canSelectCustomAddress
Indicates whether a buyer can select a custom address. When true, this implies extensions can update the delivery address.
boolean
export interface DeliveryCartInstructions {
/**
* Indicates whether a buyer can select a custom address.
*
* When true, this implies extensions can update the delivery address.
*/
canSelectCustomAddress: boolean;
}
DiscountsCartInstructions
- canUpdateDiscountCodes
Indicates whether or not discount codes can be updated.
boolean
export interface DiscountsCartInstructions {
/**
* Indicates whether or not discount codes can be updated.
*/
canUpdateDiscountCodes: boolean;
}
CartLinesCartInstructions
- canAddCartLine
Indicates whether or not new cart lines can be added.
boolean
- canRemoveCartLine
Indicates whether or not cart lines can be removed.
boolean
- canUpdateCartLine
Indicates whether or not cart lines can be updated.
boolean
export interface CartLinesCartInstructions {
/**
* Indicates whether or not new cart lines can be added.
*/
canAddCartLine: boolean;
/**
* Indicates whether or not cart lines can be removed.
*/
canRemoveCartLine: boolean;
/**
* Indicates whether or not cart lines can be updated.
*/
canUpdateCartLine: boolean;
}
MetafieldsCartInstructions
- canDeleteCartMetafield
Indicates whether or not cart metafields can be deleted.
boolean
- canSetCartMetafields
Indicates whether or not cart metafields can be added or updated.
boolean
export interface MetafieldsCartInstructions {
/**
* Indicates whether or not cart metafields can be added or updated.
*/
canSetCartMetafields: boolean;
/**
* Indicates whether or not cart metafields can be deleted.
*/
canDeleteCartMetafield: boolean;
}
NotesCartInstructions
- canUpdateNote
Indicates whether or not notes can be updated.
boolean
export interface NotesCartInstructions {
/**
* Indicates whether or not notes can be updated.
*/
canUpdateNote: boolean;
}
Discounts
Preact
Examples
Discounts
Description
Check `instructions.discounts.canUpdateDiscountCodes` before calling `applyDiscountCodeChange()`.
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> ); } }
Anchor to examplesExamples
Use the cart instructions API to determine if the affected APIs are available in checkout.
Anchor to example-attributesAttributes
Check before calling
.
Anchor to example-deliveryDelivery
Check before calling
. When
true
, this instruction implies that extensions can change the shipping address.
Anchor to example-discountsDiscounts
Check before calling
.
Check or
or
before calling
.
Anchor to example-metafieldsMetafields
Check or
before calling
if you are working with cart metafields.
Check before calling
.
Attributes
Preact
Examples
Attributes
Description
Check `instructions.attributes.canUpdateAttributes` before calling `applyAttributeChange()`.
Preact
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; export default function extension() { render(<Extension />, document.body); } function Extension() { if ( shopify.instructions.value.attributes .canUpdateAttributes ) { return ( <s-button onClick={() => shopify.applyAttributeChange({ type: 'updateAttribute', key: 'loyaltyPoints', value: '100', }) } > Apply 100 loyalty points </s-button> ); } else { return ( <s-banner tone="warning"> Loyalty points are unavailable </s-banner> ); } }
Delivery
Description
Check `instructions.delivery.canSelectCustomAddress` before calling `applyShippingAddressChange()`. When `true`, this instruction implies that extensions can change the shipping address.
Preact
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; export default function extension() { render(<Extension />, document.body); } function Extension() { if ( shopify.instructions.value.delivery .canSelectCustomAddress ) { return ( <s-button onClick={() => shopify.applyShippingAddressChange({ type: 'updateShippingAddress', address: { zip: '90201', }, }) } > Change your postal code </s-button> ); } else { return ( <s-banner tone="warning"> Shipping address cannot be modified </s-banner> ); } }
Discounts
Description
Check `instructions.discounts.canUpdateDiscountCodes` before calling `applyDiscountCodeChange()`.
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> ); } }
Lines
Description
Check `instructions.lines.canAddCartLine` or `instructions.lines.canRemoveCartLine` or `instructions.lines.canUpdateCartLine` before calling `applyCartLinesChange()`.
Preact
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; export default function extension() { render(<Extension />, document.body); } function Extension() { if ( shopify.instructions.value.lines .canAddCartLine ) { return ( <s-button onClick={() => shopify.applyCartLinesChange({ type: 'addCartLine', merchandiseId: 'gid://shopify/product/1234', quantity: 1, }) } > Add a free gift to your order </s-button> ); } else { return ( <s-banner tone="warning"> The products in your cart cannot be modified </s-banner> ); } }
Metafields
Description
Check `instructions.metafields.canSetCartMetafields` or `instructions.metafields.canDeleteCartMetafields` before calling `applyMetafieldChange()` if you are working with cart metafields.
Preact
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; export default function extension() { render(<Extension />, document.body); } function Extension() { if ( shopify.instructions.value.metafields .canSetCartMetafields ) { return ( <s-button onClick={() => shopify.applyMetafieldChange({ type: 'updateCartMetafield', metafield: { namespace: 'loyalty', key: 'loyaltyPoints', value: '100', type: 'string', }, }) } > Apply 100 loyalty points </s-button> ); } else { return ( <s-banner tone="warning"> Loyalty points are unavailable </s-banner> ); } }
Notes
Description
Check `instructions.notes.canUpdateNote` before calling `applyNoteChange()`.
Preact
import '@shopify/ui-extensions/preact'; import {render} from 'preact'; export default function extension() { render(<Extension />, document.body); } function Extension() { if ( shopify.instructions.value.notes.canUpdateNote ) { return ( <s-button onClick={() => shopify.applyNoteChange({ type: 'updateNote', note: 'Please include a free gift.', }) } > Include a free gift with your order </s-button> ); } else { return ( <s-banner tone="warning"> Free gifts cannot be added to this order </s-banner> ); } }