> For the complete documentation index, see [llms.txt](https://developer.paddle.com/llms.txt).

# Pass a discount code to Paddle.js

We added a new parameter and HTML data attribute to Paddle.js to let you pass a discount code when opening a checkout.

---

## What's new?

We added a new parameter to the [`Paddle.Checkout.open()`](https://developer.paddle.com/paddlejs/methods/paddle-checkout-open.md) method that you can use to pass a discount code to [Paddle.js](https://developer.paddle.com/paddlejs/overview.md) when [opening a checkout](https://developer.paddle.com/build/checkout/pass-update-checkout-items.md):

- **discountCode** (string or null): Discount code to apply to this checkout. Use to pre-populate a discount. Pass either `discountCode` or `discountId`.. Example: `BF20OFF`

We also added a corresponding [HTML data attribute](https://developer.paddle.com/paddlejs/html-data-attributes.md):

- **data-discount-code** (string): Discount code to apply to this checkout. Use to pre-populate a discount. Pass either `data-discount-code` or `data-discount-id`.. Example: `BF20OFF`

This complements the existing `discountId` parameter and `data-discount-id` HTML data attribute, which let you pass the Paddle ID of a discount when opening a checkout.

## How it works

Previously, you could pass `discountId` or use the `data-discount-id` HTML data attribute to pre-populate a discount when opening a checkout. These fields accept the Paddle ID of a discount entity.

The new `discountCode` parameter and `data-discount-code` HTML data attribute let you pass a discount code instead. This means that if you know the discount code for a discount, you don't need to make an additional call to the API or use the Paddle dashboard to get its ID.

Discount codes are set against [discount entities](https://developer.paddle.com/api-reference/discounts/overview.md) in Paddle. They're optional, letting you create a customer-facing code that customers can enter at Checkout, sometimes called "coupons."

## Examples

{% accordion %}
{% accordion-item title="Paddle.Checkout.open()" %}

This example shows a discount code passed to [`Paddle.Checkout.open()`](https://developer.paddle.com/paddlejs/methods/paddle-checkout-open.md).

There's no `settings` object, so checkout settings must be included in [`Paddle.Initialize()`](https://developer.paddle.com/paddlejs/methods/paddle-initialize.md).

<!-- Example showing discountCode being passed to Paddle.Checkout.open() -->
```javascript {% title="New parameter for Paddle.Checkout.open()" highlightLines="14" %}
var itemsList = [
  {
    priceId: 'pri_01gm81eqze2vmmvhpjg13bfeqg',
    quantity: 1
  },
  {
    priceId: 'pri_01gm82kny0ad1tk358gxmsq87m',
    quantity: 1
  }
];

Paddle.Checkout.open({
  items: itemsList,
  discountCode: "BF20OFF"
});
```

{% /accordion-item %}
{% accordion-item title="HTML data attributes" %}

This example shows a discount code being passed as an [HTML data attribute](https://developer.paddle.com/paddlejs/html-data-attributes.md) against a Paddle Checkout element.

It includes checkout settings and items.

<!-- Example showing data-discount-code on a checkout element -->
```html {% title="New HTML data attribute" highlightLines="17" %}
<a href='#' 
  class='paddle_button'
  data-display-mode='overlay'
  data-theme='light'
  data-locale='en'
  data-allow-logout='false'
  data-items='[
    {
      "priceId": "pri_01gm81eqze2vmmvhpjg13bfeqg",
      "quantity": 1
    },
    {
      "priceId": "pri_01gm82kny0ad1tk358gxmsq87m",
      "quantity": 1
    }
  ]'
  data-discount-code='BF20OFF'
>
  Buy now
</a>
```

{% /accordion-item %}
{% /accordion %}

## Next steps

This change is live in Paddle.js now, so you can start using `discountCode` or `data-discount-code` when you're ready.

You don't need to do anything to get the latest version of Paddle.js — we serve the latest version automatically.
## Summary of changes

| Name | Type | Change | Entity | Description |
| --- | --- | --- | --- | --- |
| `discountCode` | Paddle.js param | added | Paddle.Checkout.open() | Discount code to apply to this checkout. Pass either `discountCode` or `discountId`. |
| `data-discount-code` | Paddle.js param | added | HTML data attributes | Discount code to apply to this checkout. Pass either `data-discount-code` or `data-discount-id`. |
