Can you send a discount code link?

Is it possible to send a discount code link so a user can have a discount code automatically applied by following the link rather than copy-pasting it? If so, what’s the base URL for it?

Hey @manifesto,

Unfortunately, this isn’t something we support. We recommend sending the code by email so that the customer can add it to the cart.

As Charles has mentioned, this is not supported out-of-the-box.

If I may offer a suggestion:
You could accomplish this with the JavaScript cart APIs. If you can edit/add JavaScript to use the window.SnipcartApi object, then you could pull the discount code from the URL and automatically apply it to the cart via window.Snipcart.api.cart.applyDiscount(discountCode)

4 Likes

I’m trying to get this to work, and it does, but only after the page is refreshed or after the customer adds a second item to their cart.

If they just add a single item and check out, the discount is not applied. But if they add the item, then refresh the page, or if they add the item, then add another item, the discount is applied.

Any suggestions on how to make this work straight away? Here’s the code I’m using:

<script>
    document.addEventListener('snipcart.ready', async function() {
      try {
        await Snipcart.api.cart.applyDiscount('10-PERCENT-2022');
        } catch (error) {
            console.log(error);
        }
    });
</script>