Discount Code Input Methods
SmartCart.applyDiscount ⇒ void
Applies a discount code to the current SmartCart instance.
| Param |
Type |
Description |
| discountCode |
string |
The discount code to apply. |
| [e] |
Event |
The event object (optional). |
Example
// Apply a discount code programmatically
SmartCart.applyDiscount('SAVE10');
// Apply from a custom input field
const code = document.querySelector('#my-discount-input').value;
if (code) {
SmartCart.applyDiscount(code);
}
SmartCart.getApplicableDiscountCodeTotal ⇒ number
Gets the applicable discount amount from a submitted discount code. Used in the Tiered Progress Bar calculations.
Returns: number - The applicable discount amount from the submitted discount code ## SmartCart.getDiscountButtonLabel ⇒ string
Get the discount button label from the current SmartCart instance
Returns: string - The discount button text ## SmartCart.getDiscountCodeLabel ⇒ string
Get the discount code label from the current SmartCart instance
Returns: string - The discount code label text ## SmartCart.getDiscountCodeSettings ⇒ object | null
Get the discount code settings from the current SmartCart instance
Returns: object | null - The discount code component settings ## SmartCart.getDiscountInvalidMessage ⇒ string
Get the discount invalid message from the current SmartCart instance
Returns: string - The discount invalid message text ## SmartCart.isDiscountInputEnabled ⇒ boolean
Determines if the discount code input component is enabled.
Example
// Check if discount input is enabled before showing custom UI
if (SmartCart.isDiscountInputEnabled()) {
document.querySelector('.custom-discount-section').style.display = 'block';
}
SmartCart.removeDiscount ⇒ void
Removes the discount from the current SmartCart instance + local storage.
Example
// Remove any applied discount code
SmartCart.removeDiscount();
console.log('Discount code removed');
SmartCart.shouldApplyDiscountCode ⇒ boolean
Determines, based on the presence of an automatic discount, if the discount code should be applied.
Returns: boolean - Whether the discount code should be applied. ## SmartCart.shouldShowDiscountEntitled ⇒ boolean
Determines if the discount entitled message should be shown.
Returns: boolean - Whether the discount entitled message should be shown. ## SmartCart.shouldShowDiscountInput ⇒ boolean
Determines if the discount input should be shown.
Returns: boolean - Whether the discount input should be shown. ## SmartCart.shouldShowDiscountSubtotal ⇒ boolean
Determines if the discount subtotal should be shown.
Returns: boolean - Whether the discount subtotal should be shown. ## SmartCart.showInvalidMessage ⇒ boolean
Determines if the invalid message should be shown.
Returns: boolean - Whether the invalid message should be shown. ## SmartCart.useDiscountCodeMessageOnly ⇒ boolean
Determines if the discount calculation should be omitted (useful for complex discount scenarios).
Returns: boolean - Whether the discount calculation should be omitted until checkout.
---
title: Discount Code Input Methods
excerpt: Apply and validate discount codes in the cart drawer
deprecated: false
hidden: false
metadata:
title: ''
description: ''
robots: index
next:
description: Return to the New Methods Overview Page to see other available methods.
pages:
- type: endpoint
slug: smart-cart-methods
title: Methods Overview - New
---
## `SmartCart.applyDiscount` ⇒ `void`
Applies a discount code to the current SmartCart instance.
| Param | Type | Description |
| --- | --- | --- |
| discountCode | `string` | The discount code to apply. |
| [e] | `Event` | The event object (optional). |
**Example**
```javascript
// Apply a discount code programmatically
SmartCart.applyDiscount('SAVE10');
// Apply from a custom input field
const code = document.querySelector('#my-discount-input').value;
if (code) {
SmartCart.applyDiscount(code);
}
```
## `SmartCart.getApplicableDiscountCodeTotal` ⇒ `number`
Gets the applicable discount amount from a submitted discount code. Used in the Tiered Progress Bar calculations.
**Returns**: `number` - The applicable discount amount from the submitted discount code\ ## `SmartCart.getDiscountButtonLabel` ⇒ `string`
Get the discount button label from the current SmartCart instance
**Returns**: `string` - The discount button text\ ## `SmartCart.getDiscountCodeLabel` ⇒ `string`
Get the discount code label from the current SmartCart instance
**Returns**: `string` - The discount code label text\ ## `SmartCart.getDiscountCodeSettings` ⇒ `object` | `null`
Get the discount code settings from the current SmartCart instance
**Returns**: `object` | `null` - The discount code component settings\ ## `SmartCart.getDiscountInvalidMessage` ⇒ `string`
Get the discount invalid message from the current SmartCart instance
**Returns**: `string` - The discount invalid message text\ ## `SmartCart.isDiscountInputEnabled` ⇒ `boolean`
Determines if the discount code input component is enabled.
**Example**
```javascript
// Check if discount input is enabled before showing custom UI
if (SmartCart.isDiscountInputEnabled()) {
document.querySelector('.custom-discount-section').style.display = 'block';
}
```
## `SmartCart.removeDiscount` ⇒ `void`
Removes the discount from the current SmartCart instance + local storage.
**Example**
```javascript
// Remove any applied discount code
SmartCart.removeDiscount();
console.log('Discount code removed');
```
## `SmartCart.shouldApplyDiscountCode` ⇒ `boolean`
Determines, based on the presence of an automatic discount, if the discount code should be applied.
**Returns**: `boolean` - Whether the discount code should be applied.\ ## `SmartCart.shouldShowDiscountEntitled` ⇒ `boolean`
Determines if the discount entitled message should be shown.
**Returns**: `boolean` - Whether the discount entitled message should be shown.\ ## `SmartCart.shouldShowDiscountInput` ⇒ `boolean`
Determines if the discount input should be shown.
**Returns**: `boolean` - Whether the discount input should be shown.\ ## `SmartCart.shouldShowDiscountSubtotal` ⇒ `boolean`
Determines if the discount subtotal should be shown.
**Returns**: `boolean` - Whether the discount subtotal should be shown.\ ## `SmartCart.showInvalidMessage` ⇒ `boolean`
Determines if the invalid message should be shown.
**Returns**: `boolean` - Whether the invalid message should be shown.\ ## `SmartCart.useDiscountCodeMessageOnly` ⇒ `boolean`
Determines if the discount calculation should be omitted (useful for complex discount scenarios).
**Returns**: `boolean` - Whether the discount calculation should be omitted until checkout.