Skip to content

Discount Code Input Methods

SmartCart.applyDiscountvoid

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.getApplicableDiscountCodeTotalnumber

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.getDiscountButtonLabelstring

Get the discount button label from the current SmartCart instance

Returns: string - The discount button text ## SmartCart.getDiscountCodeLabelstring

Get the discount code label from the current SmartCart instance

Returns: string - The discount code label text ## SmartCart.getDiscountCodeSettingsobject | null

Get the discount code settings from the current SmartCart instance

Returns: object | null - The discount code component settings ## SmartCart.getDiscountInvalidMessagestring

Get the discount invalid message from the current SmartCart instance

Returns: string - The discount invalid message text ## SmartCart.isDiscountInputEnabledboolean

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.removeDiscountvoid

Removes the discount from the current SmartCart instance + local storage.

Example

// Remove any applied discount code
SmartCart.removeDiscount();
console.log('Discount code removed');

SmartCart.shouldApplyDiscountCodeboolean

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.shouldShowDiscountEntitledboolean

Determines if the discount entitled message should be shown.

Returns: boolean - Whether the discount entitled message should be shown. ## SmartCart.shouldShowDiscountInputboolean

Determines if the discount input should be shown.

Returns: boolean - Whether the discount input should be shown. ## SmartCart.shouldShowDiscountSubtotalboolean

Determines if the discount subtotal should be shown.

Returns: boolean - Whether the discount subtotal should be shown. ## SmartCart.showInvalidMessageboolean

Determines if the invalid message should be shown.

Returns: boolean - Whether the invalid message should be shown. ## SmartCart.useDiscountCodeMessageOnlyboolean

Determines if the discount calculation should be omitted (useful for complex discount scenarios).

Returns: boolean - Whether the discount calculation should be omitted until checkout.

See something that needs updating? Suggest an edit