<p>If a coupon triggers an error, that error is part of the cart element. It's accessed as <code>couponCode</code>
This is from a Craft 3 project (4 i believe is same):</p>
<pre><code> {% set firstCouponCodeNotice = cart.getFirstNotice(null, 'couponCode') %}
 {% if firstCouponCodeNotice %}
      &lt;div class=&quot;errors&quot;&gt;
          {{ firstCouponCodeNotice }}
      &lt;/div&gt;
  {% endif %}
</code></pre>
<p>Edit: documentation link added</p>
<p><a href="https://craftcms.com/docs/commerce/4.x/orders-carts.html#order-notices" rel="nofollow noreferrer">https://craftcms.com/docs/commerce/4.x/orders-carts.html#order-notices</a></p>
<p>If you want one snippet to handle both carts and orders...</p>
<pre><code>{% set model = cart is defined ? cart : order is defined ? order : NULL %}
{% if model %}
    {% set firstCouponCodeNotice = model.getFirstNotice(null, 'couponCode') %}
    {% if firstCouponCodeNotice %}
         &lt;div class=&quot;errors&quot;&gt;
             {{ firstCouponCodeNotice }}
         &lt;/div&gt;
     {% endif %}
{% endif %}
</code></pre>

CC BY-SA 4.0
2024-03-20T21:18:01.083Z
For context, there's some discussion about how this works here: https://github.com/craftcms/commerce/issues/2491 - personally I continue to think the design of this behaviour is far from ideal.
Jeremy Daalder
CC BY-SA 4.0
2024-03-19T07:09:12.943Z
2024-03-19T07:14:50.573Z
2024-03-19T07:14:50.573Z
cherrykoda
<p>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?</p>
<p>Right now if an invalid/expired coupon is being submitted in the checkout, nothing happens and that can be confusing...</p>
<p>Any hint will be great!</p>

<plugin-craftcommerce><cart><plugin-craftcommerce4>
Displaying coupon error messages on front end commerce 4
# Displaying coupon error messages on front end commerce 4

(Asked by: username_0 on 2024-03-16)

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!

**Tags:** plugin-craftcommerce, cart, plugin-craftcommerce4


---

## 1 answers

### Answer by username_1 on 2024-03-19. Score: 2 | Accepted answer

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 %}
      
          {{ firstCouponCodeNotice }}
      
  {% 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 %}
         
             {{ firstCouponCodeNotice }}
         
     {% endif %}
{% endif %}

> **Comments:**
> **username_2**: For context, there's some discussion about how this works here: https://github.com/craftcms/commerce/issues/2491 - personally I continue to think the design of this behaviour is far from ideal.  

---

