The applyDiscount() action lets you programmatically apply a discount or coupon code to the user’s current cart within the app.
It’s useful when you want to trigger discount application directly from a custom web block — for example, from a “Apply Coupon” button, a promotional banner, or after user input validation.
When invoked, this action applies the given code to the cart and automatically updates the totals on the native checkout or cart screen.
Function Signature
Superfans.actions.applyDiscount([code]) //code -> Disocunt Code from Shopify
// Example JSON data
// Replace your discount code in json
const discountData = {
title: "WELCOME30",
code: "G7X6Xwelcome30NKSYT3G"
};
// Assign value from JSON to input field
document.getElementById("couponCode").value = discountData.title;
// Apply coupon on click function call
function applyDiscountOnCart()
{
document.getElementById("applyCoupon").disabled=true;
document.getElementById("applyCoupon").textContent ="Applied";
Superfans.actions.applyDiscount([discountData.code]);
}
applyDiscountOnCart();