Dynamically Apply Discounts

Apply a discount to your checkout automatically or when the user clicks a particular link or button

This can be used for things like:

  • Reduce checkout abandon – Show an exit-intent popup that offers a discount if they checkout

  • Incentivize repeat purchases – Automatically apply a discount for logged in users

  • Reinforce an affiliate sale – Automatically apply a discount for users referred by an affiliate

Custom code might not be needed! Spiffy will automatically apply discounts/coupons passed through the URL using ?code=MYCOUPON or ?c=MYCOUPON – this works on Spiffy.js and the hosted checkout

Apply Discount Immediately

If you want to apply a discount immediately but need some additional logic around when to apply it or what coupon to apply (eg, only apply for particular campaigns or particular affiliates) you can do so like this:

// wait for Spiffy to be ready
spiffy.on('ready', function () {
    // identify the checkout you want to apply the discount to
    spiffy.checkout("https://yourcompany.spiffy.co/checkout/test-checkout", {
        // apply the coupon!
        coupon: 'MYCOUPON'
    })
})

Using Logic with Discounts

You can leverage some logic for determine when to apply:

// wait for Spiffy to be ready
spiffy.on('ready', function () {
    // only apply the coupon sometimes...
    if (Rewardful.affiliate != null) {
        // identify the checkout you want to apply the discount to
        spiffy.checkout("https://yourcompany.spiffy.co/checkout/test-checkout", {
            // apply the coupon!
            coupon: 'MYCOUPON'
        })
    }
})

Or apply different discounts in different scenarios:

// wait for Spiffy to be ready
spiffy.on('ready', function () {
    // specific coupon per affiliate
    if (Rewardful.affiliate == 'Jon Snow') {
        var affiliateCoupon = 'A-JONSNOW'
    }
    
    // identify the checkout you want to apply the discount to
    spiffy.checkout("https://yourcompany.spiffy.co/checkout/test-checkout", {
        // apply the coupon!
        coupon: affiliateCoupon
    })
})

Apply Discount on Interaction

In some cases you may prompt a user to 'claim' a discount or promotion (eg, an exit popup). To do this you can simply use native click event listeners on a buttons, links, and any other elements to apply your discount.

// wait for Spiffy to be ready
spiffy.on('ready', function () {
    
    // save the checkout object to a variable
    var checkout = spiffy.checkout("https://yourcompany.spiffy.co/checkout/test-checkout")
    
    // get the button or link
    var button = document.getElementById('couponButton')
    
    // tell the button what to do when clicked
    button.onclick = function () {
        checkout.update({ coupon: 'MYCOUPON' })
    }
})

All of these same ideas and methods work for doing all sorts of things to your checkouts such as setting the customer, etc!

Last updated