<p>I think this one is debatable from a functional perspective.</p>
<p>On first glance, it feels like if a cart is emptied then the coupon should be removed, but on the flip side, if they are simply changing their order and the cart is emptied along the way during that process, why should they have to re-enter the coupon?  The coupon itself is still valid, so if they have entered it, and then the cart later becomes valid for that coupon, why should it not then automatically re-apply?</p>
<p>I believe the only way to clear the coupon code as you wish would be to detect if the cart is empty (i.e. has no lineitems) and then post (e.g. by ajax) to <code>update-cart</code> an empty coupon code...something like:</p>
<pre><code>&lt;form method=&quot;POST&quot; id=&quot;remove-coupon&quot;&gt;
    {{ csrfInput() }}
    {{ redirectInput('/cart') }}
    &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;commerce/cart/update-cart&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;couponCode&quot; value=&quot;&quot;&gt;
    ...etc
</code></pre>

CC BY-SA 4.0
2020-09-16T02:45:13.703Z
2020-09-16T02:45:13.703Z
Jeremy Daalder
<p>Is there anyway to remove all the discounts if cart becomes empty?</p>

<plugin-craftcommerce><plugin-craftcommerce2><ecommerce><cart>
Empty cart should remove coupon discounts in commerce
# Empty cart should remove coupon discounts in commerce

(Asked by: username_0 on 2020-09-13)

Is there anyway to remove all the discounts if cart becomes empty?

**Tags:** plugin-craftcommerce, plugin-craftcommerce2, ecommerce, cart

---

## 1 answers

### Answer by username_1 on 2020-09-16. Score: 1

I think this one is debatable from a functional perspective.
On first glance, it feels like if a cart is emptied then the coupon should be removed, but on the flip side, if they are simply changing their order and the cart is emptied along the way during that process, why should they have to re-enter the coupon?  The coupon itself is still valid, so if they have entered it, and then the cart later becomes valid for that coupon, why should it not then automatically re-apply?
I believe the only way to clear the coupon code as you wish would be to detect if the cart is empty (i.e. has no lineitems) and then post (e.g. by ajax) to update-cart an empty coupon code...something like:

    {{ csrfInput() }}
    {{ redirectInput('/cart') }}
    
    
    ...etc


---

