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


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:

<form method="POST" id="remove-coupon">
    {{ csrfInput() }}
    {{ redirectInput('/cart') }}
    <input type="hidden" name="action" value="commerce/cart/update-cart">
    <input type="hidden" name="couponCode" value="">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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