Magento 2 remove coupon code programmatically

Today we talk about how Magento 2 remove a coupon code programmatically. You can get quote data from the checkout cart model. You can remove the coupon on the current cart. So let’s start with our example.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;

class ApplyCoupon extends Action
{

protected $cart;

public function __construct(
\Magento\Checkout\Model\Cart $cart
)
{
$this->cart = $cart;
}

public function applyCoupon()
{

$coupon = "";
return $this->cart->getQuote()->setCouponCode($coupon)->collectTotals()->save();

}
}

 

Search

Recent Blogs

Categories

Archives

Archives

Tags