Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-20T21:18:01.083Z
Answers.Text: 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.
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-03-19T07:09:12.943Z
Answers.LastActivityDate: 2024-03-19T07:14:50.573Z
Answers.LastEditDate: 2024-03-19T07:14:50.573Z
Answers.UserDisplayName: cherrykoda
Body: <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>
  
Tags: <plugin-craftcommerce><cart><plugin-craftcommerce4>
Title: Displaying coupon error messages on front end commerce 4
ThreadText: # 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 %}
        <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 %}
  
  ```
  
  > **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.  
  
  ---
  
  