Cart API
The Cart API provides comprehensive access to POS cart management functionality, enabling extensions to read cart state, modify line items, apply discounts, manage customer information, and handle cart properties. The API supports both individual and bulk operations for efficient cart manipulation, with selling plan functionality and error handling.
Use cases
- Real-time monitoring: Monitor cart changes to update extension UI and respond to modifications.
- Discounts: Apply custom discounts at cart and line item levels, including percentage-based and codes.
- Product management: Add products programmatically with oversell protection and error handling.
- Selling plans: Manage selling plans and subscription products with comprehensive operations.
Supported targets
- pos.
cart. line-item-details. action. menu-item. render - pos.
cart. line-item-details. action. render - pos.
customer-details. action. menu-item. render - pos.
customer-details. action. render - pos.
customer-details. block. render - pos.
draft-order-details. action. menu-item. render - pos.
draft-order-details. action. render - pos.
draft-order-details. block. render - pos.
home. modal. render - pos.
home. tile. render - pos.
order-details. action. menu-item. render - pos.
order-details. action. render - pos.
order-details. block. render - pos.
product-details. action. menu-item. render - pos.
product-details. action. render - pos.
product-details. block. render
Anchor to cartapiCartApi
The object provides access to cart management functionality and real-time cart state monitoring. Access these properties through shopify.cart to interact with the current POS cart.
- Anchor to addAddressaddAddress(address: Address) => Promise<void>required
Add a new address to the customer associated with the cart. The customer must be present in the cart before adding addresses with enhanced address validation and formatting.
- Anchor to addCartCodeDiscountaddCartCodeDiscount(code: string) => Promise<void>required
Apply a discount code to the cart. The system will validate the code and apply the appropriate discount if the code is valid and applicable to the current cart contents with improved error messaging.
- Anchor to addCartPropertiesaddCartProperties(properties: Record<string, string>) => Promise<void>required
Add custom key-value properties to the cart for storing metadata, tracking information, or integration data. Properties are merged with existing cart properties with enhanced validation and conflict resolution.
- Anchor to addCustomSaleaddCustomSale(customSale: CustomSale) => Promise<string>required
Add a custom sale item to the cart with specified quantity, title, price, and taxable status. Returns the
of the created line item for future operations and property management.- Anchor to addLineItemaddLineItem(variantId: number, quantity: number) => Promise<string>required
Add a product variant to the cart by its numeric
with the specified quantity. Returns theof the newly added line item, or an empty string if the user dismissed an oversell guard modal. Throws an error if POS fails to add the line item due to validation or system errors.- Anchor to addLineItemPropertiesaddLineItemProperties(uuid: string, properties: Record<string, string>) => Promise<void>required
Add custom properties to a specific line item using its
. Properties are merged with existing line item properties for metadata storage and tracking with enhanced validation.- Anchor to addLineItemSellingPlanaddLineItemSellingPlan(input: SetLineItemSellingPlanInput) => Promise<void>required
Add a selling plan to a line item in the cart using the line item
, selling plan, and selling plan name. Optionally provide delivery interval and interval count for improved performance, otherwise POS will fetch them after syncing the cart.- Anchor to applyCartDiscountapplyCartDiscount(type: CartDiscountType, title: string, amount?: string) => Promise<void>required
Apply a cart-level discount with the specified type (
'Percentage',, or'Code'), title, and optional amount. For discount codes, omit theamountparameter. Enhanced validation ensures proper discount application.- Anchor to bulkAddLineItemPropertiesbulkAddLineItemProperties(lineItemProperties: SetLineItemPropertiesInput[]) => Promise<void>required
Add properties to multiple line items simultaneously using an array of inputs containing line item
and their respective properties for efficient bulk operations with enhanced validation and error reporting.- Anchor to bulkCartUpdatebulkCartUpdate(cartState: CartUpdateInput) => Promise<Cart>required
Perform a bulk update of the entire cart state including note, discounts, customer, line items, and properties. Returns the updated cart object after the operation completes with enhanced validation and error handling.
- Anchor to bulkSetLineItemDiscountsbulkSetLineItemDiscounts(lineItemDiscounts: SetLineItemDiscountInput[]) => Promise<void>required
Apply discounts to multiple line items simultaneously. Each input specifies the line item
and discount details for efficient bulk discount operations with enhanced validation and allocation tracking.- Anchor to clearCartclearCart() => Promise<void>required
Remove all line items and reset the cart to an empty state. This action can't be undone and will clear all cart contents including line items, discounts, properties, and selling plans.
- Anchor to currentcurrentReadonlySignalLike<Cart>required
Provides read-only access to the current cart state and allows subscribing to cart changes. The
valueproperty provides the current cart state, andsubscribeallows listening to changes with improved performance and memory management.- Anchor to deleteAddressdeleteAddress(addressId: number) => Promise<void>required
Delete an existing address from the customer using the address
. The customer must be present in the cart to perform this operation with improved error handling for invalid address.- Anchor to removeAllDiscountsremoveAllDiscounts(disableAutomaticDiscounts: boolean) => Promise<void>required
Remove all discounts from both the cart and individual line items. Set
totrueto prevent automatic discounts from being reapplied after removal with enhanced discount allocation handling.- Anchor to removeCartDiscountremoveCartDiscount() => Promise<void>required
Remove the current cart-level discount. This only affects cart-level discounts and does not impact line item discounts or automatic discount eligibility.
- Anchor to removeCartPropertiesremoveCartProperties(keys: string[]) => Promise<void>required
Remove specific cart properties by their keys. Only the specified property keys will be removed while other properties remain intact with improved error handling for non-existent keys.
- Anchor to removeCustomerremoveCustomer() => Promise<void>required
Remove the currently associated customer from the cart, converting it back to a guest cart without customer-specific benefits or information while preserving cart contents.
- Anchor to removeLineItemremoveLineItem(uuid: string) => Promise<void>required
Remove a specific line item from the cart using its
. The line item will be completely removed from the cart along with any associated discounts, properties, or selling plans.- Anchor to removeLineItemDiscountremoveLineItemDiscount(uuid: string) => Promise<void>required
Remove all discounts from a specific line item identified by its
. This will clear any custom discounts applied to the line item while preserving discount allocation history.- Anchor to removeLineItemPropertiesremoveLineItemProperties(uuid: string, keys: string[]) => Promise<void>required
Remove specific properties from a line item by
and property keys. Only the specified keys will be removed while other properties remain intact with improved error handling.- Anchor to removeLineItemSellingPlanremoveLineItemSellingPlan(uuid: string) => Promise<void>required
Remove the selling plan from a line item in the cart using the line item
. This will clear any subscription or recurring purchase configuration from the line item.- Anchor to setAttributedStaffsetAttributedStaff(staffId: number) => Promise<void>required
Set the attributed staff member for all line items in the cart using the staff
. Passundefinedto clear staff attribution from all line items with enhanced staff validation and tracking.- Anchor to setAttributedStaffToLineItemsetAttributedStaffToLineItem(staffId: number, lineItemUuid: string) => Promise<void>required
Set the attributed staff member for a specific line item using the staff
and line item. Passundefinedasto clear attribution from the line item with improved validation and error handling.- Anchor to setCustomersetCustomer(customer: Customer) => Promise<void>required
Associate a customer with the current cart using the customer object containing the customer
. This enables customer-specific pricing, discounts, and checkout features with enhanced customer data validation.- Anchor to setLineItemDiscountsetLineItemDiscount(uuid: string, type: LineItemDiscountType, title: string, amount: string) => Promise<void>required
Apply a discount to a specific line item using its
. Specify the discount type ('Percentage'or), title, and amount value with improved discount allocation tracking.- Anchor to updateDefaultAddressupdateDefaultAddress(addressId: number) => Promise<void>required
Set a specific address as the default address for the customer using the address
. The customer must be present in the cart to update the default address with enhanced validation.
Address
Represents physical address information for customer shipping and billing. Contains standard address fields including street, city, region, postal code, and country data.
- address1
The primary street address line. Required for most shipping and billing operations. Should contain street number and name.
string - address2
The secondary address line for apartment, suite, or unit information. Optional field for additional address details.
string - city
The city name for the address. Required for shipping calculations and location-based services.
string - company
The company name associated with the address. Optional field for business customers and B2B transactions.
string - country
The country name for the address. Required for international shipping, tax calculations, and compliance.
string - countryCode
The standardized country code (ISO format). Use for precise country identification and international shipping operations.
CountryCode - firstName
The first name for the address contact. Used for personalized shipping labels and customer communication.
string - lastName
The last name for the address contact. Required for complete customer identification and shipping labels.
string - name
The full name for the address contact. Use when first and last names are combined or unavailable as separate fields.
string - phone
The phone number for the address contact. Used for delivery notifications, shipping updates, and customer communication.
string - province
The province or state name for the address. Required for regional shipping rates and tax calculations.
string - provinceCode
The standardized province or state code. Use for precise regional identification and automated shipping calculations.
string - zip
The postal or ZIP code for the address. Required for accurate shipping rates and location-based services.
string
export interface Address {
/**
* The primary street address line. Required for most shipping and billing operations. Should contain street number and name.
*/
address1?: string;
/**
* The secondary address line for apartment, suite, or unit information. Optional field for additional address details.
*/
address2?: string;
/**
* The city name for the address. Required for shipping calculations and location-based services.
*/
city?: string;
/**
* The company name associated with the address. Optional field for business customers and B2B transactions.
*/
company?: string;
/**
* The first name for the address contact. Used for personalized shipping labels and customer communication.
*/
firstName?: string;
/**
* The last name for the address contact. Required for complete customer identification and shipping labels.
*/
lastName?: string;
/**
* The phone number for the address contact. Used for delivery notifications, shipping updates, and customer communication.
*/
phone?: string;
/**
* The province or state name for the address. Required for regional shipping rates and tax calculations.
*/
province?: string;
/**
* The country name for the address. Required for international shipping, tax calculations, and compliance.
*/
country?: string;
/**
* The postal or ZIP code for the address. Required for accurate shipping rates and location-based services.
*/
zip?: string;
/**
* The full name for the address contact. Use when first and last names are combined or unavailable as separate fields.
*/
name?: string;
/**
* The standardized province or state code. Use for precise regional identification and automated shipping calculations.
*/
provinceCode?: string;
/**
* The standardized country code (ISO format). Use for precise country identification and international shipping operations.
*/
countryCode?: CountryCode;
}CountryCode
- AF
AF - AX
AX - AL
AL - DZ
DZ - AD
AD - AO
AO - AI
AI - AG
AG - AR
AR - AM
AM - AW
AW - AC
AC - AU
AU - AT
AT - AZ
AZ - BS
BS - BH
BH - BD
BD - BB
BB - BY
BY - BE
BE - BZ
BZ - BJ
BJ - BM
BM - BT
BT - BO
BO - BA
BA - BW
BW - BV
BV - BR
BR - IO
IO - BN
BN - BG
BG - BF
BF - BI
BI - KH
KH - CA
CA - CV
CV - BQ
BQ - KY
KY - CF
CF - TD
TD - CL
CL - CN
CN - CX
CX - CC
CC - CO
CO - KM
KM - CG
CG - CD
CD - CK
CK - CR
CR - HR
HR - CU
CU - CW
CW - CY
CY - CZ
CZ - CI
CI - DK
DK - DJ
DJ - DM
DM - DO
DO - EC
EC - EG
EG - SV
SV - GQ
GQ - ER
ER - EE
EE - SZ
SZ - ET
ET - FK
FK - FO
FO - FJ
FJ - FI
FI - FR
FR - GF
GF - PF
PF - TF
TF - GA
GA - GM
GM - GE
GE - DE
DE - GH
GH - GI
GI - GR
GR - GL
GL - GD
GD - GP
GP - GT
GT - GG
GG - GN
GN - GW
GW - GY
GY - HT
HT - HM
HM - VA
VA - HN
HN - HK
HK - HU
HU - IS
IS - IN
IN - ID
ID - IR
IR - IQ
IQ - IE
IE - IM
IM - IL
IL - IT
IT - JM
JM - JP
JP - JE
JE - JO
JO - KZ
KZ - KE
KE - KI
KI - KP
KP - XK
XK - KW
KW - KG
KG - LA
LA - LV
LV - LB
LB - LS
LS - LR
LR - LY
LY - LI
LI - LT
LT - LU
LU - MO
MO - MG
MG - MW
MW - MY
MY - MV
MV - ML
ML - MT
MT - MQ
MQ - MR
MR - MU
MU - YT
YT - MX
MX - MD
MD - MC
MC - MN
MN - ME
ME - MS
MS - MA
MA - MZ
MZ - MM
MM - NA
NA - NR
NR - NP
NP - NL
NL - AN
AN - NC
NC - NZ
NZ - NI
NI - NE
NE - NG
NG - NU
NU - NF
NF - MK
MK - NO
NO - OM
OM - PK
PK - PS
PS - PA
PA - PG
PG - PY
PY - PE
PE - PH
PH - PN
PN - PL
PL - PT
PT - QA
QA - CM
CM - RE
RE - RO
RO - RU
RU - RW
RW - BL
BL - SH
SH - KN
KN - LC
LC - MF
MF - PM
PM - WS
WS - SM
SM - ST
ST - SA
SA - SN
SN - RS
RS - SC
SC - SL
SL - SG
SG - SX
SX - SK
SK - SI
SI - SB
SB - SO
SO - ZA
ZA - GS
GS - KR
KR - SS
SS - ES
ES - LK
LK - VC
VC - SD
SD - SR
SR - SJ
SJ - SE
SE - CH
CH - SY
SY - TW
TW - TJ
TJ - TZ
TZ - TH
TH - TL
TL - TG
TG - TK
TK - TO
TO - TT
TT - TA
TA - TN
TN - TR
TR - TM
TM - TC
TC - TV
TV - UG
UG - UA
UA - AE
AE - GB
GB - US
US - UM
UM - UY
UY - UZ
UZ - VU
VU - VE
VE - VN
VN - VG
VG - WF
WF - EH
EH - YE
YE - ZM
ZM - ZW
ZW - ZZ
ZZ
export enum CountryCode {
AF = 'AF',
AX = 'AX',
AL = 'AL',
DZ = 'DZ',
AD = 'AD',
AO = 'AO',
AI = 'AI',
AG = 'AG',
AR = 'AR',
AM = 'AM',
AW = 'AW',
AC = 'AC',
AU = 'AU',
AT = 'AT',
AZ = 'AZ',
BS = 'BS',
BH = 'BH',
BD = 'BD',
BB = 'BB',
BY = 'BY',
BE = 'BE',
BZ = 'BZ',
BJ = 'BJ',
BM = 'BM',
BT = 'BT',
BO = 'BO',
BA = 'BA',
BW = 'BW',
BV = 'BV',
BR = 'BR',
IO = 'IO',
BN = 'BN',
BG = 'BG',
BF = 'BF',
BI = 'BI',
KH = 'KH',
CA = 'CA',
CV = 'CV',
BQ = 'BQ',
KY = 'KY',
CF = 'CF',
TD = 'TD',
CL = 'CL',
CN = 'CN',
CX = 'CX',
CC = 'CC',
CO = 'CO',
KM = 'KM',
CG = 'CG',
CD = 'CD',
CK = 'CK',
CR = 'CR',
HR = 'HR',
CU = 'CU',
CW = 'CW',
CY = 'CY',
CZ = 'CZ',
CI = 'CI',
DK = 'DK',
DJ = 'DJ',
DM = 'DM',
DO = 'DO',
EC = 'EC',
EG = 'EG',
SV = 'SV',
GQ = 'GQ',
ER = 'ER',
EE = 'EE',
SZ = 'SZ',
ET = 'ET',
FK = 'FK',
FO = 'FO',
FJ = 'FJ',
FI = 'FI',
FR = 'FR',
GF = 'GF',
PF = 'PF',
TF = 'TF',
GA = 'GA',
GM = 'GM',
GE = 'GE',
DE = 'DE',
GH = 'GH',
GI = 'GI',
GR = 'GR',
GL = 'GL',
GD = 'GD',
GP = 'GP',
GT = 'GT',
GG = 'GG',
GN = 'GN',
GW = 'GW',
GY = 'GY',
HT = 'HT',
HM = 'HM',
VA = 'VA',
HN = 'HN',
HK = 'HK',
HU = 'HU',
IS = 'IS',
IN = 'IN',
ID = 'ID',
IR = 'IR',
IQ = 'IQ',
IE = 'IE',
IM = 'IM',
IL = 'IL',
IT = 'IT',
JM = 'JM',
JP = 'JP',
JE = 'JE',
JO = 'JO',
KZ = 'KZ',
KE = 'KE',
KI = 'KI',
KP = 'KP',
XK = 'XK',
KW = 'KW',
KG = 'KG',
LA = 'LA',
LV = 'LV',
LB = 'LB',
LS = 'LS',
LR = 'LR',
LY = 'LY',
LI = 'LI',
LT = 'LT',
LU = 'LU',
MO = 'MO',
MG = 'MG',
MW = 'MW',
MY = 'MY',
MV = 'MV',
ML = 'ML',
MT = 'MT',
MQ = 'MQ',
MR = 'MR',
MU = 'MU',
YT = 'YT',
MX = 'MX',
MD = 'MD',
MC = 'MC',
MN = 'MN',
ME = 'ME',
MS = 'MS',
MA = 'MA',
MZ = 'MZ',
MM = 'MM',
NA = 'NA',
NR = 'NR',
NP = 'NP',
NL = 'NL',
AN = 'AN',
NC = 'NC',
NZ = 'NZ',
NI = 'NI',
NE = 'NE',
NG = 'NG',
NU = 'NU',
NF = 'NF',
MK = 'MK',
NO = 'NO',
OM = 'OM',
PK = 'PK',
PS = 'PS',
PA = 'PA',
PG = 'PG',
PY = 'PY',
PE = 'PE',
PH = 'PH',
PN = 'PN',
PL = 'PL',
PT = 'PT',
QA = 'QA',
CM = 'CM',
RE = 'RE',
RO = 'RO',
RU = 'RU',
RW = 'RW',
BL = 'BL',
SH = 'SH',
KN = 'KN',
LC = 'LC',
MF = 'MF',
PM = 'PM',
WS = 'WS',
SM = 'SM',
ST = 'ST',
SA = 'SA',
SN = 'SN',
RS = 'RS',
SC = 'SC',
SL = 'SL',
SG = 'SG',
SX = 'SX',
SK = 'SK',
SI = 'SI',
SB = 'SB',
SO = 'SO',
ZA = 'ZA',
GS = 'GS',
KR = 'KR',
SS = 'SS',
ES = 'ES',
LK = 'LK',
VC = 'VC',
SD = 'SD',
SR = 'SR',
SJ = 'SJ',
SE = 'SE',
CH = 'CH',
SY = 'SY',
TW = 'TW',
TJ = 'TJ',
TZ = 'TZ',
TH = 'TH',
TL = 'TL',
TG = 'TG',
TK = 'TK',
TO = 'TO',
TT = 'TT',
TA = 'TA',
TN = 'TN',
TR = 'TR',
TM = 'TM',
TC = 'TC',
TV = 'TV',
UG = 'UG',
UA = 'UA',
AE = 'AE',
GB = 'GB',
US = 'US',
UM = 'UM',
UY = 'UY',
UZ = 'UZ',
VU = 'VU',
VE = 'VE',
VN = 'VN',
VG = 'VG',
WF = 'WF',
EH = 'EH',
YE = 'YE',
ZM = 'ZM',
ZW = 'ZW',
ZZ = 'ZZ',
}CustomSale
Represents a custom sale item that is not associated with a product in the catalog. Includes pricing, taxation, and descriptive information for manually created line items.
- price
The price for the custom sale item as currency string. Must be a valid positive amount. Use for non-catalog items and custom pricing.
string - quantity
The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management.
number - taxable
Determines whether the custom sale item is taxable. Set to `true` to apply tax calculations, `false` to exempt from taxes.
boolean - title
The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly.
string
export interface CustomSale {
/**
* The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management.
*/
quantity: number;
/**
* The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly.
*/
title: string;
/**
* The price for the custom sale item as currency string. Must be a valid positive amount. Use for non-catalog items and custom pricing.
*/
price: string;
/**
* Determines whether the custom sale item is taxable. Set to `true` to apply tax calculations, `false` to exempt from taxes.
*/
taxable: boolean;
}SetLineItemSellingPlanInput
Specifies the parameters for assigning selling plans to line items. Used to add subscription or purchase option configurations to products.
- lineItemUuid
The target line item `UUID` for selling plan assignment. Must match an existing line item in the cart.
string - sellingPlanId
The selling plan `ID` to apply to the line item. Must be a valid selling plan available for the product.
number - sellingPlanName
The selling plan name for display purposes. Required for proper selling plan display in the cart.
string
export interface SetLineItemSellingPlanInput {
/**
* The target line item `UUID` for selling plan assignment. Must match an existing line item in the cart.
*/
lineItemUuid: string;
/**
* The selling plan `ID` to apply to the line item. Must be a valid selling plan available for the product.
*/
sellingPlanId: number;
/**
* The selling plan name for display purposes. Required for proper selling plan display in the cart.
*/
sellingPlanName?: string;
}CartDiscountType
Defines the type of discount applied at the cart level. Specifies whether the discount is percentage-based, fixed amount, or discount code redemption.
'Percentage' | 'FixedAmount' | 'Code'SetLineItemPropertiesInput
Specifies the parameters for adding custom properties to line items. Properties are key-value pairs used for storing metadata, tracking information, or integration data.
- lineItemUuid
The target line item `UUID` for selling plan assignment. Must match an existing line item in the cart.
string - properties
The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values.
Record<string, string>
export interface SetLineItemPropertiesInput {
/**
* The target line item `UUID` for selling plan assignment. Must match an existing line item in the cart.
*/
lineItemUuid: string;
/**
* The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values.
*/
properties: Record<string, string>;
}CartUpdateInput
Specifies the parameters for updating cart information. Includes options for modifying customer data, notes, references, and other cart-level metadata.
- cartDiscount
The cart-level discount to apply during bulk update. Replaces existing cart discount. Set to `undefined` to remove current discount.
Discount - cartDiscounts
An array of cart-level discounts to apply during bulk update. Replaces all existing cart discounts with the provided array.
Discount[] - customer
The customer to associate with the cart during bulk update. Replaces existing customer or converts guest cart to customer cart.
Customer - lineItems
An array of line items to set during bulk update. Completely replaces existing cart contents—removes all current items and adds the provided ones.
LineItem[] - note
The cart note to set during bulk update. Replaces existing note or sets new note if none exists. Set to `undefined` to remove current note.
string - properties
The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values.
Record<string, string>
export interface CartUpdateInput {
/**
* The cart note to set during bulk update. Replaces existing note or sets new note if none exists. Set to `undefined` to remove current note.
*/
note?: string;
/**
* The cart-level discount to apply during bulk update. Replaces existing cart discount. Set to `undefined` to remove current discount.
*/
cartDiscount?: Discount;
/**
* An array of cart-level discounts to apply during bulk update. Replaces all existing cart discounts with the provided array.
*/
cartDiscounts: Discount[];
/**
* The customer to associate with the cart during bulk update. Replaces existing customer or converts guest cart to customer cart.
*/
customer?: Customer;
/**
* An array of line items to set during bulk update. Completely replaces existing cart contents—removes all current items and adds the provided ones.
*/
lineItems: LineItem[];
/**
* The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values.
*/
properties: Record<string, string>;
}Discount
Represents a discount applied to a cart or transaction, including amount and description.
- amount
The discount value to apply. For `'Percentage'` type, this represents the percentage value (For example, "10" for 10% off). For `'FixedAmount'` type, this represents the fixed monetary amount to deduct from the line item price. Commonly used for discount calculations and displaying the discount value to merchants.
number - currency
The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code associated with the location currently active on POS.
string - discountDescription
A human-readable description of the discount shown to merchants and customers. This typically includes the discount name, promotion details, or discount code (for example, "SUMMER2024", "10% off entire order", "Buy 2 Get 1 Free"). Returns `undefined` when no description is provided.
string - type
The [discount type](https://help.shopify.com/en/manual/discounts/discount-types) applied to this line item. Can be either `'Percentage'` for percentage-based discounts or `'FixedAmount'` for fixed monetary amount discounts. This determines how the discount amount is calculated and displayed.
string
export interface Discount {
/**
* The discount value to apply. For `'Percentage'` type, this represents the percentage value (For example, "10" for 10% off). For `'FixedAmount'` type, this represents the fixed monetary amount to deduct from the line item price. Commonly used for discount calculations and displaying the discount value to merchants.
*/
amount: number;
/**
* The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code associated with the location currently active on POS.
*/
currency?: string;
/**
* A human-readable description of the discount shown to merchants and customers. This typically includes the discount name, promotion details, or discount code (for example, "SUMMER2024", "10% off entire order", "Buy 2 Get 1 Free"). Returns `undefined` when no description is provided.
*/
discountDescription?: string;
/**
* The [discount type](https://help.shopify.com/en/manual/discounts/discount-types) applied to this line item. Can be either `'Percentage'` for percentage-based discounts or `'FixedAmount'` for fixed monetary amount discounts. This determines how the discount amount is calculated and displayed.
*/
type?: string;
}Customer
Represents basic customer identification information. Contains the customer ID for linking to detailed customer data and enabling customer-specific features.
- id
The unique numeric identifier for the customer in Shopify's system. This ID is consistent across all Shopify systems and APIs. Used to link this customer reference to the full customer record with complete profile information. Commonly used for customer lookups, applying customer-specific pricing or discounts, linking orders to customer accounts, or integrating with customer management systems.
number
export interface Customer {
/**
* The unique numeric identifier for the customer in Shopify's system. This ID is consistent across all Shopify systems and APIs. Used to link this customer reference to the full customer record with complete profile information. Commonly used for customer lookups, applying customer-specific pricing or discounts, linking orders to customer accounts, or integrating with customer management systems.
*/
id: number;
}LineItem
Represents an individual item in the shopping cart. Contains product information, pricing, quantity, discounts, and customization details for a single cart entry.
- attributedUserId
The staff member 'ID' attributed to this line item. Returns 'undefined' if no staff attribution is set. Use for commission tracking and performance analytics.
number - components
Bundle components for this line item. Only present for [product bundles](/docs/apps/build/product-merchandising/bundles). Each component represents an individual item within the bundle with its own tax information.
LineItemComponent[] - discountAllocations
An array of discount allocations applied to this line item, providing detailed breakdown of how discounts are distributed. Returns 'undefined' if no allocations exist. Use for enhanced discount tracking and reporting.
DiscountAllocation[] - discounts
An array of discounts applied to this line item. Empty array if no discounts are active. Use for displaying line item savings and discount details.
Discount[] - hasSellingPlanGroups
Determines whether this line item has selling plan groups (subscription options) available. Returns 'undefined' if selling plan information is unavailable. Use for displaying subscription options.
boolean - isGiftCard
Determines whether this line item is a gift card. Gift cards have special handling requirements and business logic. Use for implementing gift card-specific workflows.
boolean - price
The unit price of the line item. Returns 'undefined' for custom sales without set prices. Use for pricing calculations and displays.
number - productId
The product 'ID' this line item represents. Returns 'undefined' for custom sales or non-product items. Use for product-specific operations and linking to product details.
number - properties
The custom key-value properties attached to this line item. Empty object if no properties are set. Use for metadata, customization options, or integration data.
{ [key: string]: string; } - quantity
The quantity of this item in the cart. Always a positive integer. Use for quantity displays, calculations, and inventory management.
number - requiresSellingPlan
Determines whether this line item requires a selling plan (subscription) to be purchased. Returns 'undefined' if selling plan information is unavailable. Use for implementing subscription-based product handling.
boolean - sellingPlan
The currently selected selling plan for this line item. Returns 'undefined' if no selling plan is applied. Contains selling plan details including 'ID', name, and delivery intervals. Use for subscription management and recurring purchase functionality.
SellingPlan - sku
The Stock Keeping Unit (SKU) identifier for this line item. Returns 'undefined' if no SKU is configured. Use for inventory tracking and product identification.
string - taxable
Determines whether this line item is subject to tax calculations. Use for tax computation, compliance, and pricing displays.
boolean - taxLines
An array of tax lines applied to this line item, containing tax amounts and rates. Use for detailed tax reporting and compliance.
TaxLine[] - title
The display title of the line item. Returns 'undefined' for items without titles. Use for customer-facing displays and cart item identification.
string - uuid
The unique identifier for this line item within the cart. Use for line item-specific operations like updates, removals, or property modifications.
string - variantId
The product variant 'ID' this line item represents. Returns 'undefined' for custom sales or non-variant items. Use for variant-specific operations and product details.
number - vendor
The vendor or brand name for this line item. Returns 'undefined' if no vendor is set. Use for vendor-specific displays and organization.
string
export interface LineItem {
/**
* The unique identifier for this line item within the cart. Use for line item-specific operations like updates, removals, or property modifications.
*/
uuid: string;
/**
* The unit price of the line item. Returns 'undefined' for custom sales without set prices. Use for pricing calculations and displays.
*/
price?: number;
/**
* The quantity of this item in the cart. Always a positive integer. Use for quantity displays, calculations, and inventory management.
*/
quantity: number;
/**
* The display title of the line item. Returns 'undefined' for items without titles. Use for customer-facing displays and cart item identification.
*/
title?: string;
/**
* The product variant 'ID' this line item represents. Returns 'undefined' for custom sales or non-variant items. Use for variant-specific operations and product details.
*/
variantId?: number;
/**
* The product 'ID' this line item represents. Returns 'undefined' for custom sales or non-product items. Use for product-specific operations and linking to product details.
*/
productId?: number;
/**
* An array of discounts applied to this line item. Empty array if no discounts are active. Use for displaying line item savings and discount details.
*/
discounts: Discount[];
/**
* An array of discount allocations applied to this line item, providing detailed breakdown of how discounts are distributed. Returns 'undefined' if no allocations exist. Use for enhanced discount tracking and reporting.
*/
discountAllocations?: DiscountAllocation[];
/**
* Determines whether this line item is subject to tax calculations. Use for tax computation, compliance, and pricing displays.
*/
taxable: boolean;
/**
* An array of tax lines applied to this line item, containing tax amounts and rates. Use for detailed tax reporting and compliance.
*/
taxLines: TaxLine[];
/**
* The Stock Keeping Unit (SKU) identifier for this line item. Returns 'undefined' if no SKU is configured. Use for inventory tracking and product identification.
*/
sku?: string;
/**
* The vendor or brand name for this line item. Returns 'undefined' if no vendor is set. Use for vendor-specific displays and organization.
*/
vendor?: string;
/**
* The custom key-value properties attached to this line item. Empty object if no properties are set. Use for metadata, customization options, or integration data.
*/
properties: {[key: string]: string};
/**
* Determines whether this line item is a gift card. Gift cards have special handling requirements and business logic. Use for implementing gift card-specific workflows.
*/
isGiftCard: boolean;
/**
* The staff member 'ID' attributed to this line item. Returns 'undefined' if no staff attribution is set. Use for commission tracking and performance analytics.
*/
attributedUserId?: number;
/**
* Determines whether this line item requires a selling plan (subscription) to be purchased. Returns 'undefined' if selling plan information is unavailable. Use for implementing subscription-based product handling.
*/
requiresSellingPlan?: boolean;
/**
* Determines whether this line item has selling plan groups (subscription options) available. Returns 'undefined' if selling plan information is unavailable. Use for displaying subscription options.
*/
hasSellingPlanGroups?: boolean;
/**
* The currently selected selling plan for this line item. Returns 'undefined' if no selling plan is applied. Contains selling plan details including 'ID', name, and delivery intervals. Use for subscription management and recurring purchase functionality.
*/
sellingPlan?: SellingPlan;
/**
* Bundle components for this line item. Only present for [product bundles](/docs/apps/build/product-merchandising/bundles). Each component represents an individual item within the bundle with its own tax information.
*/
components?: LineItemComponent[];
}LineItemComponent
Represents a component of a [product bundle](/docs/apps/build/product-merchandising/bundles) line item. Bundle components contain the individual items that make up a bundle, each with their own pricing and tax information.
- price
The price for the custom sale item as currency string. Must be a valid positive amount. Use for non-catalog items and custom pricing.
number - productId
The unique numeric identifier for the product this component represents, if applicable.
number - quantity
The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management.
number - taxable
Determines whether the custom sale item is taxable. Set to `true` to apply tax calculations, `false` to exempt from taxes.
boolean - taxLines
An array of tax lines applied to this component.
TaxLine[] - title
The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly.
string - variantId
The unique numeric identifier for the product variant this component represents, if applicable.
number
export interface LineItemComponent {
/**
* The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly.
*/
title?: string;
/**
* The quantity of the custom sale item. Must be a positive integer. Use for quantity-based pricing and inventory management.
*/
quantity: number;
/**
* The price for the custom sale item as currency string. Must be a valid positive amount. Use for non-catalog items and custom pricing.
*/
price?: number;
/**
* Determines whether the custom sale item is taxable. Set to `true` to apply tax calculations, `false` to exempt from taxes.
*/
taxable: boolean;
/**
* An array of tax lines applied to this component.
*/
taxLines: TaxLine[];
/**
* The unique numeric identifier for the product variant this component represents, if applicable.
*/
variantId?: number;
/**
* The unique numeric identifier for the product this component represents, if applicable.
*/
productId?: number;
}TaxLine
Represents a tax line applied to an item or transaction.
- enabled
Whether this tax is currently enabled.
boolean - price
The tax amount as a Money object.
Money - rate
The tax rate as a decimal number.
number - rateRange
The range of tax rates if applicable.
{ min: number; max: number; } - title
The title or name of the tax.
string - uuid
The unique identifier for this tax line.
string
export interface TaxLine {
/**
* The title or name of the tax.
*/
title: string;
/**
* The tax amount as a Money object.
*/
price: Money;
/**
* The tax rate as a decimal number.
*/
rate: number;
/**
* The unique identifier for this tax line.
*/
uuid?: string;
/**
* The range of tax rates if applicable.
*/
rateRange?: {min: number; max: number};
/**
* Whether this tax is currently enabled.
*/
enabled?: boolean;
}Money
Represents a monetary amount with currency information.
- amount
The monetary amount as a number.
number - currency
The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code associated with the location currently active on POS.
string
export interface Money {
/**
* The monetary amount as a number.
*/
amount: number;
/**
* The [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) currency code associated with the location currently active on POS.
*/
currency: string;
}DiscountAllocation
Represents the allocation of a discount to a specific line item.
- allocatedAmount
The amount of discount allocated.
MoneyV2
export interface DiscountAllocation {
/**
* The amount of discount allocated.
*/
allocatedAmount: MoneyV2;
}MoneyV2
Represents a monetary amount as a string with explicit currency code.
- amount
The monetary amount as a string.
string - currencyCode
The ISO currency code (for example, USD, CAD).
string
export interface MoneyV2 {
/**
* The monetary amount as a string.
*/
amount: string;
/**
* The ISO currency code (for example, USD, CAD).
*/
currencyCode: string;
}SellingPlan
Represents a selling plan (subscription) associated with a line item, containing delivery schedule and plan identification details.
- deliveryInterval
The interval of the selling plan. (DAY, WEEK, MONTH, YEAR).
string - deliveryIntervalCount
The number of intervals between deliveries.
number - digest
The fingerprint of the applied selling plan within this cart session. Provided by POS. Not available during refund / exchanges.
string - id
The unique identifier of the selling plan.
number - name
The name of the POS device.
string
export interface SellingPlan {
/**
* The unique identifier of the selling plan.
*/
id: number;
/**
* The name of the POS device.
*/
name: string;
/**
* The fingerprint of the applied selling plan within this cart session. Provided by POS. Not available during refund / exchanges.
*/
digest?: string;
/**
* The interval of the selling plan. (DAY, WEEK, MONTH, YEAR).
*/
deliveryInterval?: string;
/**
* The number of intervals between deliveries.
*/
deliveryIntervalCount?: number;
}Cart
Represents the shopping cart state, including line items, pricing, customer information, and applied discounts. Provides comprehensive access to all cart data and operations.
- cartDiscount
The cart-level discount to apply during bulk update. Replaces existing cart discount. Set to `undefined` to remove current discount.
Discount - cartDiscounts
An array of cart-level discounts to apply during bulk update. Replaces all existing cart discounts with the provided array.
Discount[] - customer
The customer to associate with the cart during bulk update. Replaces existing customer or converts guest cart to customer cart.
Customer - editable
Indicates whether the cart is currently editable. An `undefined` value should be treated as `true` for backward compatibility. Use this to determine if cart modification operations are allowed.
boolean - grandTotal
The final total amount including all items, taxes, and discounts, formatted as a currency string.
string - lineItems
An array of line items to set during bulk update. Completely replaces existing cart contents—removes all current items and adds the provided ones.
LineItem[] - note
The cart note to set during bulk update. Replaces existing note or sets new note if none exists. Set to `undefined` to remove current note.
string - properties
The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values.
Record<string, string> - subtotal
The subtotal amount of the cart before taxes and discounts, formatted as a currency string.
string - taxTotal
The total tax amount for the cart, formatted as a currency string.
string
export interface Cart {
/**
* Indicates whether the cart is currently editable. An `undefined` value should be treated as `true` for backward compatibility. Use this to determine if cart modification operations are allowed.
*/
editable?: boolean;
/**
* The subtotal amount of the cart before taxes and discounts, formatted as a currency string.
*/
subtotal: string;
/**
* The total tax amount for the cart, formatted as a currency string.
*/
taxTotal: string;
/**
* The final total amount including all items, taxes, and discounts, formatted as a currency string.
*/
grandTotal: string;
/**
* The cart note to set during bulk update. Replaces existing note or sets new note if none exists. Set to `undefined` to remove current note.
*/
note?: string;
/**
* The cart-level discount to apply during bulk update. Replaces existing cart discount. Set to `undefined` to remove current discount.
*/
cartDiscount?: Discount;
/**
* An array of cart-level discounts to apply during bulk update. Replaces all existing cart discounts with the provided array.
*/
cartDiscounts: Discount[];
/**
* The customer to associate with the cart during bulk update. Replaces existing customer or converts guest cart to customer cart.
*/
customer?: Customer;
/**
* An array of line items to set during bulk update. Completely replaces existing cart contents—removes all current items and adds the provided ones.
*/
lineItems: LineItem[];
/**
* The custom key-value properties to apply to the line item. Merged with existing properties—duplicate keys overwrite existing values.
*/
properties: Record<string, string>;
}SetLineItemDiscountInput
Specifies the parameters for applying discounts to individual line items. Includes the discount type, value, and reason for audit and reporting purposes.
- lineItemDiscount
The discount details to apply to the line item. Contains title, type (`'Percentage'` or `'FixedAmount'`), and amount value.
LineItemDiscount - lineItemUuid
The target line item `UUID` for selling plan assignment. Must match an existing line item in the cart.
string
export interface SetLineItemDiscountInput {
/**
* The target line item `UUID` for selling plan assignment. Must match an existing line item in the cart.
*/
lineItemUuid: string;
/**
* The discount details to apply to the line item. Contains title, type (`'Percentage'` or `'FixedAmount'`), and amount value.
*/
lineItemDiscount: LineItemDiscount;
}LineItemDiscount
Represents a discount applied to an individual line item in the cart.
- amount
The percentage or fixed amount for the discount.
string - title
The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly.
string - type
The discount type.
'Percentage' | 'FixedAmount'
export interface LineItemDiscount {
/**
* The display name for the custom sale item. Appears on receipts and in cart displays. Should be descriptive and customer-friendly.
*/
title: string;
/**
* The discount type.
*/
type: 'Percentage' | 'FixedAmount';
/**
* The percentage or fixed amount for the discount.
*/
amount: string;
}ReadonlySignalLike
Represents a reactive signal interface that provides both immediate value access and subscription-based updates. Enables real-time synchronization with changing data through the observer pattern.
- subscribe
Subscribes to locale changes and calls the provided function whenever the locale updates. Returns an unsubscribe function to clean up the subscription. Use to automatically update your extension content when merchants change their language settings during POS sessions.
(fn: (value: T) => void) => () => void - value
The current value of the locale string in IETF format. For example, `"en-US"`, `"fr-CA"`, or `"de-DE"`. This property provides immediate access to the current locale without requiring subscription setup. Use for one-time locale checks or initial internationalization setup.
T
export interface ReadonlySignalLike<T> {
/**
* The current value of the locale string in IETF format. For example, `"en-US"`, `"fr-CA"`, or `"de-DE"`. This property provides immediate access to the current locale without requiring subscription setup. Use for one-time locale checks or initial internationalization setup.
*/
readonly value: T;
/**
* Subscribes to locale changes and calls the provided function whenever the locale updates. Returns an unsubscribe function to clean up the subscription. Use to automatically update your extension content when merchants change their language settings during POS sessions.
*/
subscribe(fn: (value: T) => void): () => void;
}LineItemDiscountType
Defines the type of discount applied to individual line items. Specifies whether the discount is percentage-based or a fixed amount reduction.
'Percentage' | 'FixedAmount'jsx
Examples
Add a custom sale item to the cart
Description
Add a custom item to the cart with manual pricing and details. This example demonstrates using `shopify.cart.addCustomSale()` to create custom line items for services, fees, or items not in the product catalog. This provides flexibility for unique sales scenarios.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.addCustomSale({ taxable: true, quantity: 1, title: 'T-shirt', price: '10.00', }); }} /> ); };Add a new address to the customer
Description
Create a new address for the customer associated with the cart. This example demonstrates using `shopify.cart.addAddress()` to add shipping or billing addresses to customer profiles. This simplifies future purchases and enables multiple delivery locations.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.addAddress({ address1: '123 Main St', city: 'Ottawa', province: 'Ontario', zip: 'K1S 5B6', firstName: 'John', lastName: 'Doe', country: 'Canada', phone: '555-1234', }); }} /> ); };Add a product to the cart
Description
Add a product variant to the cart with specified quantity and optional properties. This example shows how to use `shopify.cart.addLineItem()` to add catalog items to the cart with custom attributes. This enables standard product sales with additional customization.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.addLineItem(12345678, 1); }} /> ); };Add a subscription selling plan to a line item
Description
Associate a subscription or selling plan with a line item for recurring purchases. This example shows how to use `shopify.cart.addLineItemSellingPlan()` to add selling plans to items. This enables subscription-based sales and recurring revenue models.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.addLineItemSellingPlan({ lineItemUuid: 'aa-1234567', sellingPlanId: 123, sellingPlanName: 'My Exclusive Subscription', }); }} /> ); };Add custom properties to a line item
Description
Attach custom metadata to a specific line item for additional product information. This example shows how to use `shopify.cart.addLineItemProperties()` to add key-value properties to individual items. This enables customization like engraving text, gift messages, or special instructions.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.addLineItemProperties('aa-1234567', { note: 'Handle with care', request: 'Gift wrap', }); }} /> ); };Add custom properties to the cart
Description
Attach custom metadata to the cart for additional order information. This example shows how to use `shopify.cart.addCartProperties()` to add key-value properties that persist through checkout. This is useful for tracking order sources, preferences, or workflow data.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.addCartProperties({ note: 'Handle with care', request: 'Gift wrap', }); }} /> ); };Add properties to multiple line items at once
Description
Attach custom metadata to multiple line items efficiently in a single operation. This example demonstrates using `shopify.cart.bulkAddLineItemProperties()` to add properties to several items simultaneously. This improves performance for batch customization operations.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.bulkAddLineItemProperties([ { lineItemUuid: 'aa-1234567', properties: { note: 'Handle with care', request: 'Gift wrap', }, }, { lineItemUuid: 'bb-7654321', properties: { color: 'Blue', size: 'Medium', }, }, ]); }} /> ); };Apply a cart-level discount
Description
Apply a custom discount to the entire cart using a fixed amount or percentage. This example shows how to use `shopify.cart.applyCartDiscount()` to add order-level discounts with custom reasons. This is useful for promotions, loyalty rewards, or staff discounts.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.applyCartDiscount('Percentage', 'Summer discount', '10'); }} /> ); };Apply a discount code to the cart
Description
Apply a discount code to the cart for automatic discount validation and application. This example demonstrates using `shopify.cart.applyCodeDiscount()` to add discount codes that are validated against Shopify discount rules. This enables promotional code redemption with automatic validation.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.addCartCodeDiscount('SUMMER10'); }} /> ); };Apply a discount to a line item
Description
Apply a custom discount to a specific line item in the cart. This example demonstrates using `shopify.cart.setLineItemDiscount()` to add item-level discounts with custom reasons. This is useful for selective price adjustments or item-specific promotions.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.setLineItemDiscount( 'aa-1234567', 'Percentage', 'Summer discount', '10', ); }} /> ); };Apply a percentage discount to the cart
Description
Add a cart-level discount that applies to the total cart value. This example demonstrates applying a 10% discount titled 'Summer discount' to the cart using the `applyCartDiscount()` method with the `Percentage` discount type.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.applyCartDiscount('Percentage', 'Summer discount', '10'); }} /> ); };Apply different discounts to multiple line items
Description
Apply discounts to multiple line items efficiently in a single operation. This example shows how to use `shopify.cart.bulkSetLineItemDiscounts()` to add discounts to several items simultaneously. This improves performance for bulk pricing adjustments or category-wide promotions.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.bulkSetLineItemDiscounts([ { lineItemUuid: 'aa-1234567', lineItemDiscount: { type: 'Percentage', title: 'Summer discount', amount: '10', }, }, { lineItemUuid: 'bb-7654321', lineItemDiscount: { type: 'FixedAmount', title: 'Loyalty discount', amount: '5', }, }, ]); }} /> ); };Associate a customer with the cart
Description
Assign a customer to the current cart for personalized pricing and order history. This example demonstrates using `shopify.cart.setCustomer()` to link a customer by ID. This enables customer-specific discounts, loyalty programs, and order tracking.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.setCustomer({ id: 1, }); }} /> ); };Attribute a staff member to a line item
Description
Associate a specific line item with a staff member for item-level commission tracking. This example shows how to use `shopify.cart.setAttributedStaffToLineItem()` to assign staff members to individual items. This enables granular sales attribution and performance analysis.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.setAttributedStaffToLineItem(123456, 'aa-1234567'); }} /> ); };Attribute a staff member to the cart
Description
Attribute the cart to a staff member for commission tracking and sales attribution. This example demonstrates using `shopify.cart.setAttributedStaff()` to assign staff members to sales. This enables performance tracking and commission calculations.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.setAttributedStaff(123456); }} /> ); };Check if the cart is editable
Description
Verify whether the cart is in an editable state before attempting modifications. This example demonstrates using `shopify.cart.editable` to check if the cart can accept changes. By disabling actions when the cart is locked or in an immutable state, you can prevent errors and improve the user experience.
jsx
import {render} from 'preact'; import {useState, useEffect} from 'preact/hooks'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { const [isEditable, setIsEditable] = useState( shopify.cart.current.value.editable ?? true ); useEffect(() => { const unsubscribe = shopify.cart.current.subscribe((newCart) => { setIsEditable(newCart.editable ?? true); }); return unsubscribe; }, []); return ( <s-tile heading="My App" disabled={!isEditable} /> ); };Clear all items from the cart
Description
Remove all line items and reset the cart to an empty state. This example shows how to use `shopify.cart.clear()` to completely clear the cart. This is useful for starting fresh transactions or implementing cart reset functionality.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.clearCart(); }} /> ); };Delete a customer address
Description
Remove a specific address from the customer profile using its unique identifier. This example shows how to use `shopify.cart.deleteAddress()` to delete outdated or incorrect addresses. This helps maintain clean customer records.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.deleteAddress(123456); }} /> ); };Remove a discount from a line item
Description
Remove a previously applied discount from a specific line item. This example demonstrates using `shopify.cart.removeLineItemDiscount()` to clear item-level discounts. This is useful for discount corrections or when promotional conditions are no longer met.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.removeLineItemDiscount('aa-1234567'); }} /> ); };Remove all discounts from cart and line items
Description
Clear all discounts applied to both the cart and individual line items in a single operation. This example shows how to use `shopify.cart.removeAllDiscounts()` to reset pricing to base values. This is useful for recalculating totals or canceling promotional offers.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.removeAllDiscounts(true); }} /> ); };Remove an item from the cart
Description
Remove a specific line item from the cart using its unique identifier. This example demonstrates using `shopify.cart.removeLineItem()` to delete items. This is useful for implementing remove buttons, cart cleanup, or conditional item removal logic.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.removeLineItem('aa-1234567'); }} /> ); };Remove custom properties from a line item
Description
Delete specific custom properties from a line item by their keys. This example shows how to use `shopify.cart.removeLineItemProperties()` to clear item metadata. This is useful for removing temporary customization data or outdated property values.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.removeLineItemProperties('aa-1234567', ['note']); }} /> ); };Remove custom properties from the cart
Description
Delete specific custom properties from the cart by their keys. This example demonstrates using `shopify.cart.removeCartProperties()` to clear metadata. This is useful for cleaning up temporary data or removing properties that are no longer needed.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.removeCartProperties(['note']); }} /> ); };Remove a subscription plan from a line item
Description
Remove the selling plan from a line item to convert it back to a one-time purchase. This example demonstrates using `shopify.cart.removeLineItemSellingPlan()` to clear subscription plans. This is useful when customers change their mind about recurring orders.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.removeLineItemSellingPlan('aa-1234567'); }} /> ); };Remove the customer from the cart
Description
Disassociate the customer from the current cart for anonymous transactions. This example shows how to use `shopify.cart.removeCustomer()` to clear customer information. This reverts to guest checkout pricing and removes customer-specific data from the cart.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.removeCustomer(); }} /> ); };Subscribe to real-time cart changes
Description
Monitor cart state changes in real time using the subscribe method. This example shows how to use `shopify.cart.subscribe()` to receive updates whenever the cart changes. This enables reactive UI updates, validation logic, or analytics tracking based on cart modifications.
jsx
import {render} from 'preact'; import {useState, useEffect} from 'preact/hooks'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { const [lineItemCount, setLineItemCount] = useState( shopify.cart.current.value.lineItems.length ); useEffect(() => { const unsubscribe = shopify.cart.current.subscribe((newCart) => { setLineItemCount(newCart.lineItems.length); }); return unsubscribe; }, []); return ( <s-tile heading="My App" subheading={`${lineItemCount} line items in cart`} /> ); };Update the default address for the customer
Description
Designate a specific address as the default for the customer. This example demonstrates using `shopify.cart.updateDefaultAddress()` to set the primary shipping or billing address. This simplifies the checkout process for future transactions.
jsx
import {render} from 'preact'; export default async () => { render(<Extension />, document.body); }; const Extension = () => { return ( <s-tile heading="My App" subheading="Call cart function" onClick={() => { shopify.cart.updateDefaultAddress(123456); }} /> ); };
Anchor to best-practicesBest practices
- Handle cart state reactively: Use the signal-based interface to automatically update your extension UI when cart changes occur.
- Validate operations before execution: Check cart editability and validate input data before performing cart operations to prevent errors.
- Use bulk operations for efficiency: When performing multiple related operations, use bulk methods like
,, andfor better performance and reduced API calls. - Handle errors gracefully: Implement proper error handling for all cart operations, as they may fail due to inventory constraints, validation errors, oversell protection, or business rule violations.
- Manage selling plans appropriately: When working with subscription products, validate selling plan compatibility and handle selling plan requirements.
Anchor to limitationsLimitations
Cart operations may fail due to business rules, inventory constraints, oversell protection, or validation errors—always implement appropriate error handling.