0

I am using magento 2.3.4 and and I have added one coupon code by default. I want to remove this on select of payment gateway but may be customer could add multiple coupon code , but I want to remove only one not all. So how we can do this? I dis some google and get this solution

 $quote = $observer->getEvent()->getQuote();
//remove coupon code
$quote->setCouponCode('');
$quote->collectTotals()->save();

But this will remove all the coupon. I want only one, if 2-3 coupon applied.

0

Logically, you can First get list of applied coupan codes.

$quote = $observer->getEvent()->getQuote();
$couponCode = $quote->getCouponCode();

then save existing coupans in an array. and remove all coupans

$quote->setCouponCode('');
$quote->collectTotals()->save();

then apply one by one, just don't apply desired.

$quote->setCouponCode('your_coupan');
$quote->collectTotals()->save();

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.