1

I have read in the Commerce documentation that natively, commerce doesn't display any errors when a false coupon is being entered. Did I understand the docs correctly or is there any why to achieve that? Or any plugin that deals with that?

Right now if an invalid/expired coupon is being submitted in the checkout, nothing happens and that can be confusing...

Any hint will be great!

1 Answer 1

2

If a coupon triggers an error, that error is part of the cart element. It's accessed as couponCode This is from a Craft 3 project (4 i believe is same):

 {% set firstCouponCodeNotice = cart.getFirstNotice(null, 'couponCode') %} {% if firstCouponCodeNotice %} <div class="errors"> {{ firstCouponCodeNotice }} </div> {% endif %} 

Edit: documentation link added

https://craftcms.com/docs/commerce/4.x/orders-carts.html#order-notices

If you want one snippet to handle both carts and orders...

{% set model = cart is defined ? cart : order is defined ? order : NULL %} {% if model %} {% set firstCouponCodeNotice = model.getFirstNotice(null, 'couponCode') %} {% if firstCouponCodeNotice %} <div class="errors"> {{ firstCouponCodeNotice }} </div> {% endif %} {% endif %} 
1
  • For context, there's some discussion about how this works here: github.com/craftcms/commerce/issues/2491 - personally I continue to think the design of this behaviour is far from ideal. Commented Mar 20, 2024 at 21:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.