“ Automatically apply discounts for your customers when they use your link.”
Shopify recently introduced new feature Shareable Discount Links that allows discount codes to be shared using a link.
Most important thing to know is that right now you can't grab the applied discount with Liquid. As cool as that would be to have, there's just no object that reveals that. I think the perfect - or crazy - world for a front end dev would be to have access to:
- The code name,
- The price rules that go along with it.
- Whether it can be applied to the current cart and customer
That last one would be pure magic but can see how that breaks the flow of codes working during in the checkout - but not before. Perfect world doesn't mean it's a sound idea.
Anyway, back on topic!
One handy feature that shareable discounts has, is the redirect option. We can hijack that in a way to let us pull in the some custom string data. The idea is very simple:
- Create a shareable discount.
- Use the redirect option (more info on the official docs page), making sure the url has a hash or querystring in it.
- Once you've got that code, you can then use it however you like in the theme UI.
To make it clearer you'd start with a standard shareable discount code...
...and then add the redirect code:
When used the page will redirect to the home page with the querystring (?code=fake-code) let in place. Use JS to grab it and do cool stuff. Do remember that just because you have the code doesn't mean that it's valid, nor that it can apply to the cart. Always be mindful of that so you don't end up adding confusion or setting wrong expectations on cart price for the customer.
- Something to say
- Listing things in a list
- Pay close attention to number 4
- What happens next will shock you