website logo
Navigate through spaces
⌘K
OVERVIEW
ORDER MANAGEMENT (OMS)
CONTENT MANAGEMENT (CMS)
DATA
CUSTOMER LIFETIME REVENUE
Customer Lifetime Revenue Explanation
Customer Lifetime Revenue and Purchase Likelihood
Recency Frequency and Monetary
CLR and RFM Data Table Glossary
RFM and CLR in the Hub
LOOKER
Modifying a Dashboard
Timestamp differences between Looker, OMS and Shopify
How to create custom calculations in Looker
Looker and Shopify data models
Custom fields
How to 'Save and Schedule' reports
Creating Custom Reports or Look
Looks vs Dashboards
Login Looker FAQ
Looker Glossary
SEGMENT EVENT TRACKING
What are event tracking
Adding Tracking
What is the Tracking Plan?
The Chord Tracking Plan
The Shopify Tracking Plan
Event Tracking FAQ
EVENT UPDATES PAGE
Email Subscription Payment Event Update
Product Feed Setup
Getting Segment to Production
Consent Management
Installing in Next.js
Installing in Gatsby
Integrations
👩‍💻Developer Tools
Using Chord with Shopify
Docs powered by
Archbee
Using Chord with Shopify
...
Next.js
SDK Reference

useCart

21min

The useCart hook returns information about the current shopping cart, and functions for creating and updating the shopping cart.

Example

useCart


Returns

The useCart hook returns an object with these properties:

Property

Description

cart

An object representing the current order.

addPromoCode

A function that applies a promo code to the current order.

addToCart

A function that adds a product variant to the current order.

applyGiftCard

A function that applies a gift card to the current order.

checkout

A function that redirects the browser to Shopify checkout.

loadCart

A function that loads the current cart based on the current browser session.

modifyQuantity

A function that modifies the quantity of a line item in the cart.

removeFromCart

A function that removes a line item from the cart.

removeGiftCard

A function that removes a gift card from the current order.

removePromoCode

A function that removes an applied promo code from the cart.

Functions

addPromoCode

The addPromoCode function applies a promo code to the current order.

Arguments:

addPromoCode(promoCode)

Argument

Type

Description

promoCode

String

The promo code to apply to the current order.

Returns:

Promise<void>: A Promise that resolves when the promo code has been applied to the order and the cart object has been updated to reflect the promo code.

Example:

addPromoCode


addToCart

The addToCart function adds a product variant to the current order.

Arguments:

addToCart(variantId, quantity, placement, position, customAttributes)

Argument

Type

Description

variantId

String

The product variant Shopify ID to add to the cart.

quantity

Number

The quantity of the variant to add to the cart.

placement?

String

(Optional) A string representing the placement of the product.

position?

Number

(Optional) A number representing the position of the product in the shopping cart.

customAttributes?

Array

(Optional) An array of custom attributes ({ key: '', value: '' })







Returns:

Promise<void>: A Promise that resolves when the new line item has been added to the cart.

Example:

addToCart


applyGiftCard

The applyGiftCard function applies a gift card to the current order.

Arguments:

applyGiftCard(giftCardCode)

Argument

Type

Description

giftCardCode

String

The gift card code to apply to the current order.

Returns:

Promise<void>: A Promise that resolves when the gift card has been applied to the order and the cart object has been updated to reflect the gift card.

Example:

applyGiftCard


checkout

The checkout function redirects the browser to Shopify checkout.

Arguments:

None.

Returns:

Promise<void>: A Promise that resolves when the browser has been redirected to Shopify checkout.

Example:

checkout


loadCart

The loadCart function loads the current cart based on the current browser session. This is automatically called on every page load and with every other useCart method.

Arguments:

None.

Returns:

Promise<void>: A Promise that resolves when the cart object has been added to Redux.

Example:

loadCart


modifyQuantity

The modifyQuantity function modifies the quantity of a line item in the cart.

Arguments:

modifyQuantity(lineItemId, quantity)

Argument

Type

Description

lineItemId

String

The id of the line item to update.

quantity

Number

The desired quantity of the line item.







Returns:

Promise<void>: A Promise that resolves when the cart object has been updated in Redux.

Example:

modifyQuantity


removeFromCart

The removeFromCart function removes a line item from the cart.

Arguments:

removeFromCart(lineItemId)

Argument

Type

Description

lineItemId

String

The id of the line item to update.

Returns:

Promise<void>: A Promise that resolves when the cart object has been updated in Redux.

Example:

removeFromCart


removeGiftCard

The removeGiftCard function removes a gift card from the current order.

Arguments:

removeGiftCart(appliedGiftCardId)

Argument

Type

Description

appliedGiftCardId

String

The id of the gift card to remove.

Returns:

Promise<void>: A Promise that resolves when the cart object has been updated in Redux.

Example:

removeGiftCard


removePromoCode

The removePromoCode function removes an applied promo code from the order.

Arguments:

removePromoCode(promoCode)

Argument

Type

Description

promoCode

String

The promo code to apply to the current order.

Returns:

Promise<void>: A Promise that resolves when the promo code has been removed from the order and the cart object has been updated to reflect the promo code.

Example:

removePromoCode




Updated 03 Mar 2023
Did this page help you?
PREVIOUS
useAuth
NEXT
useTranslate
Docs powered by
Archbee
useCart