How to apply discount code to checkout automatically in ReCharge app
You may want to apply a discount code automatically at checkout rather than have your customers provide the discount code on their end. You can accomplish this in ReCharge using custom code on the cart page.
To add an automatic discount code, you would need to pass the discount code in the URL. Using Shopify Liquid/JavaScript, you could add custom code that will read the items in the cart, determine which discount to pass, and then modifies the URL to pass the discount code in the URL.
You would need to edit your Shopify Theme code and use JavaScript logic to change and redirect the URL by appending discount={{CODE NAME}}
at the end of the checkout URL.
An example checkout URL:
1 | /r/checkout?myshopify_domain=huraapps.myshopify.com&cart_token=3332dc05b70d4d833e9a3d24254c6f89&discount=SALEOFF |
The redirection to the checkout page happens within the file subscription-cart-footer.liquid
, so you would have your JavaScript append the discount to the URL on the redirect.
I’m stuck. My ReferralCandy discount codes are “once per customer”. And this from the ReCharge doc is preventing me from auto-populating the discount during checkout using your method: “This implementation does not work if the discount code is set to apply once per customer as this setting relies on the email address of the customer which is not submitted on the cart page. If you require this set-up, you would need to use the API and apply the discount code post-purchase.” https://support.rechargepayments.com/hc/en-us/articles/360008682454-Apply-discount-code-to-checkout-automatically