{"id":1477,"date":"2020-12-22T09:47:23","date_gmt":"2020-12-22T09:47:23","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/send-email-after-order-cancellation-magento-2\/"},"modified":"2025-07-17T10:13:01","modified_gmt":"2025-07-17T04:43:01","slug":"send-email-after-order-cancellation-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/send-email-after-order-cancellation-magento-2\/","title":{"rendered":"How to Send Email After Order Cancellation in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The default\u00a0Magento 2\u00a0allows the merchants to\u00a0<a href=\"https:\/\/meetanshi.com\/blog\/set-up-order-confirmation-email-in-magento-2\/\">set up order confirmation Email in Magento 2<\/a>, and also for the shipment and invoice generation. These email notifications are very important for the better customer shopping experience.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes, due to the stock unavailability or any other reasons, the admin has to cancel the order from the backend. However, when an order is cancelled from the backend, the order cancellation email is not sent to the customers. Therefore, if the admin cancels the order, and the customer does not receive an email. It affects shopping experience and lower the customer retention rate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Today, I\u2019ve come up with the solution to<strong>&nbsp;send email after order cancellation in Magento 2&nbsp;<\/strong>to better notify the customers for their cancelled orders.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Programmatic Solution to Send Email after Order Cancellation in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>events.xml<\/strong>&nbsp;at<em>&nbsp;<strong>app\/code\/Vendor\/Extension\/etc\/<\/strong><\/em><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\"?>\n&lt;config xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n        xsi:noNamespaceSchemaLocation=\"urn:magento:framework:Event\/etc\/events.xsd\">\n    &lt;event name=\"sales_order_save_after\">\n        &lt;observer name=\"sales_order_save_after\"\n                  instance=\"Vendor\\Extension\\Observer\\OrderSaveAfter\"\/>\n    &lt;\/event>\n&lt;\/config><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Create&nbsp;<strong>OrderSaveAfter.php<\/strong>&nbsp;at&nbsp;<strong><strong><em>app\/code\/Vendor\/Extension\/Observer\/<\/em><\/strong><\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Vendor\\Extension\\Observer;\n\nuse Magento\\Framework\\Event\\ObserverInterface;\nuse Magento\\Sales\\Model\\Order\\Email\\Sender\\OrderCommentSender;\n\nclass OrderSaveAfter implements ObserverInterface\n{\n\n    protected $orderCommentSender;\n\n    public function __construct(\n        OrderCommentSender $orderCommentSender\n    )\n    {\n        $this->orderCommentSender = $orderCommentSender;\n    }\n\n    public function execute(\\Magento\\Framework\\Event\\Observer $observer)\n    {\n        $order = $observer->getEvent()->getOrder();\n        if ($order->getState() == 'canceled') {\n            $this->orderCommentSender->send($order, true);\n        }\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Done!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Implementing the above solution automatically sends email notification to customers after the order is cancelled from the backend.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do consider sharing this post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The default\u00a0Magento 2\u00a0allows the merchants to\u00a0set up order confirmation Email in Magento 2, and also for the shipment and invoice generation. These email notifications are&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1477","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1477","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1477"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1477\/revisions"}],"predecessor-version":[{"id":13911,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1477\/revisions\/13911"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}