Apply a discount code automatically to checkout

Apply a discount code automatically at checkout rather than having customers provide the discount code on their end.

You can configure discount codes to be automatically applied at checkout by using custom code on the cart page. This guide provides advice on setting up an automatic discount at checkout and should be used as a reference in order for you, your team, or a recommended third-party developer to accomplish.



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 configure automatic discounts on subscription products, you will need to implement custom code.
  • This feature is not supported by Recharge as per our design policy since it requires custom coding. Configuration will require advanced Shopify liquid, and possibly HTML and JavaScript knowledge. This is not part of Recharge's standard turnkey solution.
  • This customization works with fixed amount, percentage, or shipping discount codes.
  • If the 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



You must Create a discount code in Recharge before implementing any customizations.

To add an automatic discount code, pass the discount code in the URL. Using Shopify Liquid/JavaScript, you can 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.

Edit your Shopify theme code using JavaScript logic to change and redirect the URL by appending discount={{CODE NAME}} at the end of the checkout URL.


The redirection to the checkout page happens within the file subscription-cart-footer.liquid. Modify your JavaScript code to append the discount to the URL on the redirect.

Suggested Article

Need Help? Contact Us