Magento 2 – Get Applied Coupon Code in Observer

couponcoupon-codesevent-observermagento2

I want to add a product to cart when a coupon is applied. I created an observer on event controller_action_predispatch_checkout_cart_couponPost. But I don't get the applied coupon code in observer.

Can anyone tell me how to get it? Any help will be greatly appreciated..

Best Answer

In your execute() method of your observer you can call the following code to get the coupon code:

$controller = $observer->getControllerAction();
$couponCode = $controller->getRequest()->getParam('coupon_code');
Related Topic