Applying discount code to checkout automatically
You may want to apply a discount code automatically at checkout rather than having your customers manually apply a discount code themselves. This can be accomplished in Recharge using custom code on the cart page. This guide provides an overview of setting up an automatic discount at checkout.
Automatic discounts are not supported for Recharge Checkout on BigCommerce. You may be able to use an automatic discount with custom coding. We recommend working with a third-party developer and testing the discount before proceeding.
Merchants using the Shopify Checkout Integration can use Shopify's automatic discount feature at checkout.
Before you start
- The Recharge checkout does not work with Shopify's automatic discounts and can cause duplicate discounts at checkout if applied. To add automatic discounts on your subscription products, custom code is needed.
- You must create a discount code in Recharge before implementing any customizations.
- This feature requires advanced Shopify liquid, HTML, and JavaScript knowledge. This is not part of Recharge's standard turnkey solution.
- This feature is not supported by Recharge per the design and integration policy because 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 the limit one subscription per customer setting, the discount will validate on page two of checkout after the customer enters their email address. You can also use the API and apply the discount code post-purchase as an alternative solution.
Implementation
To add an automatic discount code, you must pass the discount code to the URL of your store checkout. Using Shopify Liquid and JavaScript, you can add custom code that reads the items in the cart, determines which discount to pass, and modifies the URL of your store's checkout.
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.
Example checkout URL:
/r/checkout?myshopify_domain=bootstrap dev.myshopify.com&cart_token=5566cd50a07c3c944f9b4d42524f5f98&discount=HALFOFF
The redirection to the checkout page happens from the subscription-cart-footer.liquid
file. Use JavaScript to append the discount to the URL on the redirect in this file.