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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.