Cart APIAPIs
The Cart API enables UI Extensions to manage and interact with POS cart contents, such as discounts, line items, and customer details. It provides a comprehensive set of functions for adding and removing items, alongside a subscribable object that keeps the UI Extension updated with real-time changes to the cart.
Supporting targets
- pos.home.tile.render
- pos.home.modal.render
- pos.product-details.action.menu-item.render
- pos.product-details.action.render
- pos.product-details.block.render
- pos.customer-details.action.menu-item.render
- pos.customer-details.action.render
- pos.customer-details.block.render
- pos.order-details.action.menu-item.render
- pos.order-details.action.render
- pos.order-details.block.render
- pos.draft-order-details.action.menu-item.render
- pos.draft-order-details.action.render
- pos.draft-order-details.block.render
Anchor to cartapiCartApi
- Anchor to addAddressaddAddress(address: Address) => Promise<void>required
Add an address to the customer (Customer must be present)
- Anchor to addCartCodeDiscountaddCartCodeDiscount(code: string) => Promise<void>required
Add a code discount to the cart
- Anchor to addCartPropertiesaddCartProperties(properties: Record<string, string>) => Promise<void>required
Adds custom properties to the cart
- Anchor to addCustomSaleaddCustomSale(customSale: CustomSale) => Promise<string>required
Add a custom sale to the cart
- Anchor to addLineItemaddLineItem(variantId: number, quantity: number) => Promise<string>required
Add a line item by variant ID to the cart. Returns the uuid of the line item added, or the empty string if the user dismissed an oversell guard modal without adding anything. Throws if POS fails to add the line item. Throws if POS fails to add the line item.
- Anchor to addLineItemPropertiesaddLineItemProperties(uuid: string, properties: Record<string, string>) => Promise<void>required
Adds custom properties to the specified line item
- Anchor to addLineItemSellingPlanaddLineItemSellingPlan(input: SetLineItemSellingPlanInput) => Promise<void>required
Add a selling plan to a line item in the cart.
- Anchor to applyCartDiscountapplyCartDiscount(type: CartDiscountType, title: string, amount?: string) => Promise<void>required
Apply a cart level discount
- Anchor to bulkAddLineItemPropertiesbulkAddLineItemProperties(lineItemProperties: SetLineItemPropertiesInput[]) => Promise<void>required
Adds custom properties to multiple line items at the same time.
- Anchor to bulkCartUpdatebulkCartUpdate(cartState: CartUpdateInput) => Promise<Cart>required
Bulk update the cart
- Anchor to bulkSetLineItemDiscountsbulkSetLineItemDiscounts(lineItemDiscounts: SetLineItemDiscountInput[]) => Promise<void>required
Set line item discounts to multiple line items at the same time.
- Anchor to clearCartclearCart() => Promise<void>required
Clear the cart
- Anchor to currentcurrentReadonlySignalLike<Cart>required
Provides read-only access to the current cart state and allows subscribing to cart changes. The
value
property provides the current cart state, andsubscribe
allows listening to changes.- Anchor to deleteAddressdeleteAddress(addressId: number) => Promise<void>required
Delete an address from the customer (Customer must be present)
- Anchor to removeAllDiscountsremoveAllDiscounts(disableAutomaticDiscounts: boolean) => Promise<void>required
Remove all cart and line item discounts
- Anchor to removeCartDiscountremoveCartDiscount() => Promise<void>required
Remove the cart discount
- Anchor to removeCartPropertiesremoveCartProperties(keys: string[]) => Promise<void>required
Removes the specified cart properties
- Anchor to removeCustomerremoveCustomer() => Promise<void>required
Remove the current customer from the cart
- Anchor to removeLineItemremoveLineItem(uuid: string) => Promise<void>required
Remove the line item at this uuid from the cart
- Anchor to removeLineItemDiscountremoveLineItemDiscount(uuid: string) => Promise<void>required
Remove all discounts from a line item
- Anchor to removeLineItemPropertiesremoveLineItemProperties(uuid: string, keys: string[]) => Promise<void>required
Removes the specified line item properties
- Anchor to removeLineItemSellingPlanremoveLineItemSellingPlan(uuid: string) => Promise<void>required
Remove the selling plan from a line item in the cart.
- Anchor to setAttributedStaffsetAttributedStaff(staffId: number) => Promise<void>required
Sets an attributed staff to all line items in the cart.
- Anchor to setAttributedStaffToLineItemsetAttributedStaffToLineItem(staffId: number, lineItemUuid: string) => Promise<void>required
Sets an attributed staff to a specific line items in the cart.
- Anchor to setCustomersetCustomer(customer: Customer) => Promise<void>required
Set the customer in the cart
- Anchor to setLineItemDiscountsetLineItemDiscount(uuid: string, type: LineItemDiscountType, title: string, amount: string) => Promise<void>required
Add a discount on a line item to the cart
- Anchor to updateDefaultAddressupdateDefaultAddress(addressId: number) => Promise<void>required
Update the default address for the customer (Customer must be present)
Address
- address1
string
- address2
string
- city
string
- company
string
- country
string
- countryCode
CountryCode
- firstName
string
- lastName
string
- name
string
- phone
string
- province
string
- provinceCode
string
- zip
string
export interface Address {
address1?: string;
address2?: string;
city?: string;
company?: string;
firstName?: string;
lastName?: string;
phone?: string;
province?: string;
country?: string;
zip?: string;
name?: string;
provinceCode?: string;
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
- price
string
- quantity
number
- taxable
boolean
- title
string
export interface CustomSale {
quantity: number;
title: string;
price: string;
taxable: boolean;
}
SetLineItemSellingPlanInput
- lineItemUuid
The uuid of the line item to which the selling plan should be applied.
string
- sellingPlanId
The ID of the selling plan to apply to the line item.
number
- sellingPlanName
The name of the selling plan to apply to the line item. If not provided, POS will try to fetch it from the server after syncing the cart.
string
export interface SetLineItemSellingPlanInput {
/**
* The uuid of the line item to which the selling plan should be applied.
*/
lineItemUuid: string;
/**
* The ID of the selling plan to apply to the line item.
*/
sellingPlanId: number;
/**
* The name of the selling plan to apply to the line item.
* If not provided, POS will try to fetch it from the server after syncing the cart.
*/
sellingPlanName?: string;
}
CartDiscountType
'Percentage' | 'FixedAmount' | 'Code'
SetLineItemPropertiesInput
Parameters for adding custom properties to a line item.
- lineItemUuid
The uuid belonging to the line item which should receive the custom properties.
string
- properties
The custom properties to apply to the line item.
Record<string, string>
export interface SetLineItemPropertiesInput {
/**
* The uuid belonging to the line item which should receive the custom properties.
*/
lineItemUuid: string;
/**
* The custom properties to apply to the line item.
*/
properties: Record<string, string>;
}
CartUpdateInput
- cartDiscount
Discount
- cartDiscounts
Discount[]
- customer
Customer
- lineItems
LineItem[]
- note
string
- properties
Record<string, string>
export interface CartUpdateInput {
note?: string;
cartDiscount?: Discount;
cartDiscounts: Discount[];
customer?: Customer;
lineItems: LineItem[];
properties: Record<string, string>;
}
Discount
- amount
number
- currency
string
- discountDescription
string
- type
string
export interface Discount {
amount: number;
currency?: string;
discountDescription?: string;
type?: string;
}
Customer
- id
number
export interface Customer {
id: number;
}
LineItem
- attributedUserId
number
- discountAllocations
DiscountAllocation[]
- discounts
Discount[]
- hasSellingPlanGroups
boolean
- isGiftCard
boolean
- price
number
- productId
number
- properties
{ [key: string]: string; }
- quantity
number
- requiresSellingPlan
boolean
- sellingPlan
The currently selected selling plan for this line item.
SellingPlan
- sku
string
- taxable
boolean
- taxLines
TaxLine[]
- title
string
- uuid
string
- variantId
number
- vendor
string
export interface LineItem {
uuid: string;
price?: number;
quantity: number;
title?: string;
variantId?: number;
productId?: number;
discounts: Discount[];
discountAllocations?: DiscountAllocation[];
taxable: boolean;
taxLines: TaxLine[];
sku?: string;
vendor?: string;
properties: {[key: string]: string};
isGiftCard: boolean;
attributedUserId?: number;
requiresSellingPlan?: boolean;
hasSellingPlanGroups?: boolean;
/**
* The currently selected selling plan for this line item.
*/
sellingPlan?: SellingPlan;
}
DiscountAllocation
- allocatedAmount
MoneyV2
export interface DiscountAllocation {
allocatedAmount: MoneyV2;
}
MoneyV2
- amount
string
- currencyCode
string
export interface MoneyV2 {
amount: string;
currencyCode: string;
}
SellingPlan
Represents a selling plan associated with a line item.
- 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 selling plan.
string
export interface SellingPlan {
/**
* The unique identifier of the selling plan.
*/
id: number;
/**
* The name of the selling plan.
*/
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;
}
TaxLine
- enabled
boolean
- price
Money
- rate
number
- rateRange
{ min: number; max: number; }
- title
string
- uuid
string
export interface TaxLine {
title: string;
price: Money;
rate: number;
uuid?: string;
rateRange?: {min: number; max: number};
enabled?: boolean;
}
Money
- amount
number
- currency
string
export interface Money {
amount: number;
currency: string;
}
Cart
- cartDiscount
Discount
- cartDiscounts
Discount[]
- customer
Customer
- editable
Indicates whether the cart is currently editable. An undefined value should be treated as `true` for backward compatibility.
boolean
- grandTotal
string
- lineItems
LineItem[]
- note
string
- properties
Record<string, string>
- subtotal
string
- taxTotal
string
export interface Cart {
/**
* Indicates whether the cart is currently editable.
*
* An undefined value should be treated as `true` for backward compatibility.
*/
editable?: boolean;
subtotal: string;
taxTotal: string;
grandTotal: string;
note?: string;
cartDiscount?: Discount;
cartDiscounts: Discount[];
customer?: Customer;
lineItems: LineItem[];
properties: Record<string, string>;
}
SetLineItemDiscountInput
Parameters for adding a line item discount.
- lineItemDiscount
The discount to be applied to the line item.
LineItemDiscount
- lineItemUuid
The uuid belonging to the line item which should receive the discount.
string
export interface SetLineItemDiscountInput {
/**
* The uuid belonging to the line item which should receive the discount.
*/
lineItemUuid: string;
/**
* The discount to be applied to the line item.
*/
lineItemDiscount: LineItemDiscount;
}
LineItemDiscount
- amount
The percentage or fixed amount for the discount.
string
- title
The title of the line item discount.
string
- type
The discount type.
'Percentage' | 'FixedAmount'
export interface LineItemDiscount {
/**
* The title of the line item discount.
*/
title: string;
/**
* The discount type.
*/
type: 'Percentage' | 'FixedAmount';
/**
* The percentage or fixed amount for the discount.
*/
amount: string;
}
ReadonlySignalLike
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).
- subscribe
(fn: (value: T) => void) => () => void
- value
T
export interface ReadonlySignalLike<T> {
readonly value: T;
subscribe(fn: (value: T) => void): () => void;
}
LineItemDiscountType
'Percentage' | 'FixedAmount'
Anchor to examplesExamples
Examples of using the Cart API
Anchor to example-subscribe-to-cart-changes.Subscribe to cart changes.
Anchor to example-check-editable-state-of-the-cartCheck editable state of the cart
Anchor to example-apply-a-cart-level-discountApply a cart level discount
Anchor to example-apply-a-cart-level-discount-codeApply a cart level discount code
Anchor to example-remove-all-the-discounts-on-the-cart-and-line-itemsRemove all the discounts on the cart and line items
Anchor to example-set-a-custom-discount-on-a-line-itemSet a custom discount on a line item
Anchor to example-set-a-custom-discount-on-multiple-line-itemsSet a custom discount on multiple line items
Anchor to example-remove-a-discount-on-a-line-itemRemove a discount on a line item
Anchor to example-clear-the-entire-cartClear the entire cart
Anchor to example-set-the-customer-in-the-cartSet the customer in the cart
Anchor to example-remove-the-customer-in-the-cartRemove the customer in the cart
Anchor to example-add-a-custom-sale-to-the-cartAdd a custom sale to the cart
Anchor to example-add-a-line-item-to-the-cartAdd a line item to the cart
Anchor to example-remove-a-line-item-from-the-cartRemove a line item from the cart
Anchor to example-add-custom-properties-to-the-cartAdd custom properties to the cart
Anchor to example-remove-custom-properties-from-the-cartRemove custom properties from the cart
Anchor to example-add-custom-properties-to-a-line-itemAdd custom properties to a line item
Anchor to example-add-custom-properties-to-multiple-line-itemsAdd custom properties to multiple line items
Anchor to example-remove-custom-properties-from-a-line-itemRemove custom properties from a line item
Anchor to example-set-an-attributed-staff-member-on-the-cartSet an attributed staff member on the cart
Anchor to example-set-an-attributed-staff-member-on-a-line-itemSet an attributed staff member on a line item
Anchor to example-add-an-address-to-the-customer-in-the-cartAdd an address to the customer in the cart
Anchor to example-delete-an-address-corresponding-to-an-idDelete an address corresponding to an ID
Anchor to example-set-the-default-address-of-the-customer-in-the-cartSet the default address of the customer in the cart
Anchor to example-add-a-selling-plan-to-a-line-item-in-the-cartAdd a selling plan to a line item in the cart
Anchor to example-remove-a-selling-plan-from-a-line-item-in-the-cartRemove a selling plan from a line item in the cart
Subscribe to cart changes.
jsx
Examples
Subscribe to cart changes.
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`} /> ); };
Check editable state of the cart
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} /> ); };
Apply a cart level discount
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 cart level discount code
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'); }} /> ); };
Remove all the discounts on the cart and line items
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); }} /> ); };
Set a custom discount on a line item
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', ); }} /> ); };
Set a custom discount on multiple line items
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', }, }, ]); }} /> ); };
Remove a discount on a line item
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'); }} /> ); };
Clear the entire 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.clearCart(); }} /> ); };
Set the customer in 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.setCustomer({ id: 1, }); }} /> ); };
Remove the customer in 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(); }} /> ); };
Add a custom sale to 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.addCustomSale({ taxable: true, quantity: 1, title: 'T-shirt', price: '10.00', }); }} /> ); };
Add a line item to 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.addLineItem(12345678, 1); }} /> ); };
Remove a line item 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.removeLineItem('aa-1234567'); }} /> ); };
Add custom properties to 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.addCartProperties({ note: 'Handle with care', request: 'Gift wrap', }); }} /> ); };
Remove custom properties 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.removeCartProperties(['note']); }} /> ); };
Add custom properties to a line item
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 multiple line items
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', }, }, ]); }} /> ); };
Remove custom properties from a line item
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']); }} /> ); };
Set an attributed staff member on 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.setAttributedStaff(123456); }} /> ); };
Set an attributed staff member on a line item
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'); }} /> ); };
Add an address to the customer in 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.addAddress({ address1: '123 Main St', city: 'Ottawa', province: 'Ontario', zip: 'K1S 5B6', firstName: 'John', lastName: 'Doe', country: 'Canada', phone: '555-1234', }); }} /> ); };
Delete an address corresponding to an ID
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); }} /> ); };
Set the default address of the customer in 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.updateDefaultAddress(123456); }} /> ); };
Add a selling plan to a line item in 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.addLineItemSellingPlan({ lineItemUuid: 'aa-1234567', sellingPlanId: 123, sellingPlanName: 'My Exclusive Subscription', }); }} /> ); };
Remove a selling plan from a line item in 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.removeLineItemSellingPlan('aa-1234567'); }} /> ); };