Docs

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.

Product area

  • Catalog

Tooling

  • Paddle.js
  • Checkout

Released

June 13, 2023

Status

Released

What's new?

We added a new parameter to the Paddle.Checkout.open() method that you can use to pass a discount code to Paddle.js when opening a checkout:

discountCode string or null
Example: BF20OFF

Discount code to apply to this checkout. Use to pre-populate a discount. Pass either discountCode or discountId.

We also added a corresponding HTML data attribute:

data-discount-code string
Example: BF20OFF

Discount code to apply to this checkout. Use to pre-populate a discount. Pass either data-discount-code or data-discount-id.

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 in Paddle. They're optional, letting you create a customer-facing code that customers can enter at Checkout, sometimes called "coupons."

Examples

This example shows a discount code passed to Paddle.Checkout.open().

There's no settings object, so checkout settings must be included in Paddle.Initialize().

New parameter for Paddle.Checkout.open()
var itemsList = [
{
priceId: 'pri_01gm81eqze2vmmvhpjg13bfeqg',
quantity: 1
},
{
priceId: 'pri_01gm82kny0ad1tk358gxmsq87m',
quantity: 1
}
];
Paddle.Checkout.open({
items: itemsList,
discountCode: "BF20OFF"
});

This example shows a discount code being passed as an HTML data attribute against a Paddle Checkout element.

It includes checkout settings and items.

New HTML data attribute
<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>

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

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

Was this page helpful?