Skip to main content

Cart Instructions API

The Cart Instructions API provides flags that indicate which cart mutations are allowed in the current checkout context. Use this API to determine which mutations are available before rendering features that modify the cart.

Cart instruction flags are read-only. Your extension can't change whether a mutation is permitted. It can only check the current value and respond accordingly.

  • Gate discount features: Only render discount code UI when the checkout allows discount changes.
  • Gate attribute controls: Only show preference controls like gift wrapping when the checkout allows attribute changes.
  • Gate cart modifications: Only offer features like free gifts or quantity changes when the checkout allows line item updates.
Support
Targets (31)

The shopify global object provides cart instruction data for the current checkout. Access the following properties on shopify to check which cart mutations are allowed. Available 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 before performing any actions that might 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

Check cart instructions before calling select APIs, as > some may not be available. See the > Cart Instructions API > for more information.


  • Always check instructions before mutations: Don't call mutation methods like applyDiscountCodeChange without first verifying the corresponding instruction flag. Unchecked calls fail silently or return errors.
  • Hide features when blocked: When an instruction returns false, hide the entire feature rather than showing a disabled button. This prevents confusion about why a feature is unavailable.

  • Instruction values can change between checkout steps. A mutation that's allowed on the shipping step might be blocked on the payment step.

Was this page helpful?