Apply discount code automatically to checkout
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. This guide provides advice on setting up an automatic discount at checkout. It should be used as a reference in order for you, your team, or a recommended third-party developer to accomplish.
Note
This guide applies to the Recharge Checkout on Shopify integration. Automatic discounts are not supported on the Shopify Checkout Integration or Recharge Checkout on BigCommerce.
Before you start
- The Recharge checkout will not work with Shopify's automatic discounts and can cause duplicate discounts at checkout if applied. To accomplish automatic discounts on your subscription products, you will need to implement custom code.
- You will need to create a discount code in Recharge before implementing any customizations.
- This feature will require advanced Shopify liquid, and possibly HTML and JavaScript knowledge. This is not part of Recharge's standard turnkey solution.
- This feature is not supported by Recharge as per our design policy since it requires custom coding.
- This customization works with fixed amount, percentage, or shipping discount codes.
- If your discount code is set to limit one subscription per customer you will see an error on page one of checkout with this implementation. This setting relies on the email address of the customer which is not submitted on the cart page. If you require this setup, the discount will validate on page two of checkout once the customer enters their email address or you can use the API and apply the discount code post-purchase.
General implementation
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:
/r/checkout?myshopify_domain=bootstrap dev.myshopify.com&cart_token=5566cd50a07c3c944f9b4d42524f5f98&discount=HALFOFF
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.
Updated almost 2 years ago