Magento 2 coupon add/remove event listener

Magento 2 coupon add/remove event listener

September 3, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 coupon add/remove event listener

Solving Magento 2 Coupon Add/Remove Event Listener Challenges

As an experienced developer, I understand your frustration when an event listener works perfectly on one page but fails to function on another within the same application. When it comes to Magento 2 and coupon add/remove functions, you’re dealing with a complex e-commerce platform that requires careful handling of events.

The Current Setup

You’ve already created an event listener for controller_action_predispatch_checkout_cart_couponPost, which is working perfectly on the /checkout/cart/ page. This listener is triggered before the coupon post action, allowing you to intercept and modify the behavior of adding or removing a coupon from the cart.

However, your challenge lies in the fact that this event isn’t fired when transitioning to the payment stage, specifically on the /checkout/#payment page. The Magento 2 checkout process involves multiple stages, each with its own set of events. Understanding these events is key to adding listeners where you need them.

Identifying the Right Event

To solve your issue, we need to find an event that fires during the transition from the cart summary stage to the payment stage. My recommendation would be to use the checkout_controller_onepage_save_summary event.

This event is triggered right after the customer clicks on the “Next” button on the cart summary page and before the system proceeds to the shipping and payment stages. It provides an ideal point for you to add your coupon add/remove logic without disrupting the user experience or breaking the checkout flow.

Implementing the Event Listener

To create this event listener, follow these steps:

  1. Create a custom module in your Magento 2 installation. If you haven’t set one up yet, I recommend following our guide on Creating a Custom Magento 2 Module.

  2. In the etc/events.xml file of your custom module, add the following listener configuration:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/events.xsd">
    <event name="checkout_controller_onepage_save_summary">
        <observer name="custom_module_coupon_listener" instance="Custom\Module\Observer\CouponListener" />
    </event>
</config>

Replace Custom\Module with the actual namespace of your module.

  1. Create an observer class named CouponListener, located in the Observer directory of your custom module:
<?php

namespace Custom\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class CouponListener implements ObserverInterface
{
    public function execute(Observer $observer)
    {
        // Add your coupon add/remove logic here.
        // You can access the quote object using:
        // $quote = $observer->getQuote();
    }
}
  1. Implement your desired logic inside the execute() method of the CouponListener class.

Conclusion

In conclusion, to solve your Magento 2 coupon add/remove event listener issue, you need to target the checkout_controller_onepage_save_summary event instead of relying on a page-specific URL. This approach ensures that your listener is triggered consistently throughout the checkout process.

Remember, working with Magento 2 events requires a deep understanding of the platform’s architecture and checkout flow. If you’re facing further challenges or require additional guidance on customizing other aspects of the checkout experience, feel free to explore our Magento Development Services at Laravel Company.

With this new event listener in place, your coupon add/remove functionality should now work seamlessly across all stages of the Magento 2 checkout process.

Magento 2 Checkout Cache Security

Our network