> For the complete documentation index, see [llms.txt](https://docs.chord.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chord.co/chord-oms/shopify/developer-tools/gatsby/sdk-reference/usecart.md).

# useCart

The `useCart` hook returns a series of methods for interacting with the Shopify shopping cart.

```javascript
import { useCart } from '@chordcommerce/gatsby-theme-performance'

const {
  cart,
  addPromoCode,
  addToCart,
  applyGiftCard,
  checkout,
  loadCart,
  modifyQuantity,
  removeFromCart,
  removeGiftCard,
  removePromoCode
} = useCart()
```

### cart

Represents the current shopping cart.

**Example:**

```javascript
const { cart } = useCart()
```

### addPromoCode()

Applies a promo code to the current order.

**Example:**

```javascript
const promoCode = '50off'
await addPromoCode(promoCode)
```

### addToCart()

Adds an item to the current order.

**Example:**

```javascript
const variantId = '123'
const quantity = 1
await addToCart(variantId, quantity)
```

### applyGiftCard()

Applies a gift card to the current order.

**Example:**

```javascript
const giftCardCode = 'xxxyyyzzz'
await applyGiftCard(giftCardCode)
```

### checkout()

Redirects the browser to Shopify checkout.

**Example:**

```javascript
await checkout()
```

### loadCart()

Reloads the current shopping cart. This is automatically called on every page load and with every other `useCart` method.

**Example:**

```javascript
await loadCart()
```

### modifyQuantity()

Updates the quantity of a line item in the current order.

**Example:**

```javascript
const lineItemId = '123'
const quantity = 2
await modifyQuantity(lineItemId, quantity)
```

### modifyLineItem()

Updates a line item in the current order.

**Example:**

```javascript
const lineItemId = '123'

// update line item quantity
await modifyQuantity(lineItemId, {
  quantity: 2,
})

// update line item customAttributes
await modifyQuantity(lineItemId, {
  customAttributes: [
    {
      key: 'Est. Shipping Date',
      value: 'March 24, 2022',
    }
  ],
})
```

### removeFromCart()

Removes a line item from the current order.

**Example:**

```javascript
const lineItemId = '123'
await removeFromCart(lineItemId)
```

### removeGiftCard()

Removes a gift card from the current order.

**Example:**

```javascript
const giftCardCode = 'xxxyyyzzz'
await removeGiftCard(giftCardCode)
```

### removePromoCode()

Removes a promo code from the current order.

**Example:**

```javascript
const promoCode = '50off'
await removePromoCode(promoCode)
```

## \`\`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.chord.co/chord-oms/shopify/developer-tools/gatsby/sdk-reference/usecart.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
