Email notification for cancelled order
-
24-01-2021 - |
Frage
Hi is it also possible to get email notification for cancelled orders?
Thanks
Lösung
You can always write your own module that will do that.
You will need few ingredients for that:
Have an observer that listens on the
sales_order_save_after
event.This link explains it well
catch order place after event magento2
In this observer you will get the order object by
$order= $observer->getData('order');
and you could check if the new status iscanceled
If condition from point 1 above is true you can proceed to send an email programatically. This link offers good idea of how to do that
Andere Tipps
You will need to create a separate functionality for sending the email on order cancellation.
You can use the order_cancel_after
event for writing your email function.
You can get the order details using the order object as given below
<?php
namespace Vendor\Module\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class OrderCancellationEmail implements \Magento\Framework\Event\ObserverInterface
{
/**
*
* @param \Magento\Framework\Event\Observer $observer
* @return $this
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getData('order');
// Write your email function here
}
}