How to get order event after placing order using observer in admin side?

Please modify your code like below

    <?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

   <event name="sales_order_place_after">
       <observer name="order_data" instance="Vendor\Module\Observer\OrderData" />
   </event>
</config>

OrderData.php

class OrderData implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
     $order = $observer->getEvent()->getOrder();
     echo $order->getId();
     exit;
    }
}

make sure you place events.xml under etc/adminhtml let me know if any help needed.


For me, sales_order_save_commit_after was the only event that worked well:

  • If you need the event to be triggered in the admin area and also in the frontend, you can add the following code in etc/events.xml.
  • If you need it for the order created from admin only, you need to add the following code in etc/adminhtml/events.xml

Code:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_order_save_commit_after">
        <observer name="order_data" instance="Vendor\Module\Observer\OrderData" />
    </event>
</config>