Magento Tutorials

How to Solve “Coupon code is not valid” Error in Magento

Sometimes in Magento, the coupon codes that you set up stop working for no reason. There’s an error message saying “Coupon code xxx is not valid”. Our guide will provide several solutions to help you get your coupon codes working again.

How to Solve “Coupon code is not valid” Error

Disable Discard subsequent rules

Log into your Magento backend. Go to Marketing > Promotions > Cart Price Rules.

Magento 2 Cart Price Rules
  1. Under the Rule Information section, check Customer Groups to see if it is set correctly, or even been set at all. Normally you will want to enable it for “NOT LOGGED IN” customers. You can also try to enable it for all of the customer groups to see if the problem is still there. If after enabling all customer groups the problem still persists, move on to the next steps.
    Magento 2 rule information
  2. Under Conditions section, see if any condition exist. If there is any, check the logic to see if it prevents the coupon code from being applied.
    Magento 2 coupon conditions
  3. Under Actions section, notice the Discard subsequent rules. If it is set to Yes then it is preventing other coupon codes from being applied. You may want to set it to No. Notice that this does not stop the current coupon code from happening, but other coupon codes. So if you are having problem on your current coupon code, you may want to check your other coupon codes and set Discard subsequent rules for all of them to No.
    Magento 2 coupon actions

Edit expiration date

If you’re using an older version of Magento (< 2.4.x), chances are this is an issue with the way that you set your coupon code’s expiration date. When the expiration date is set too high (> 20 years), it actually results in a reproducible bug which prevents your coupon code from being applied. 

To get around this, you’ll need to reduce your expiration date to a more sensible period, preferably less than 20 years difference between the From and the To fields.

Magento coupon code max expiration date

Add formkey to your coupon template

formkey is added in Magento 2.2.9 and it’s possible that your current coupon template lacks this block. To add formkey into your coupon template, you’ll first need to navigate to:

vendor/magento/YOUR_THEME/Magento_Checkout/templates/cart/coupon.phtml

and inside the <form> element you’ll want to add:

<?= $block->getBlockHtml('formkey'); ?>

After this, reindex and clear your cache using:

php bin/magento indexer:reindex 
php bin/magento cache:flush

And check if the issue is resolved for you.

See also: Catalog Price Rules not working in Magento 2