gnikyt Code ramblings.

Apply, verify, and validate Shopify discount codes

Shopify doesn’t have an API to verify discounts, however, I have found a little workaround.

By making an AJAX call to /discount/(code), Shopify will set a cookie telling the checkout to auto-apply a discount on a visit to the checkout page.

Next, making an AJAX call to /checkout, we’re able to parse the HTML and determine if the discount code worked!

Here’s an example of it in action:

promo-verify

For the source code of this script, please see this repository.