How to Get Order Status in sales_order_place_after event in Magento 2

Ordering and receiving products at home are easy and look simple but it is not as easy as you think for the store owner. Because once customer place an order, it process and passes through different Magento 2 order Management statuses like New Order, Pending, Payment Processing, On Hold, Complete, Canceled. But while developing or custom coding, sometimes we need to fetch current order status like payment is successfully done or not? or to fetch order state for creating or setting up further rules and conditions to fulfill business requirements.

Here we back with a small piece of code to get Order status in sales_order_place_after event.
To do the same first you need to create observer into events.xml

After that, you need to create Observer file at following location.app\code\Vendor\Extension\Observer\OrderObserver.php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<?php

namespaceVendor\Extension\Observer;

useMagento\Framework\Event\ObserverInterface;

classOrderObserverimplementsObserverInterface

{

publicfunctionexecute(\Magento\Framework\Event\Observer$observer)

{

$statuscode=$observer->getEvent()->getOrder()->getStatus();

$statuslabel=$observer->getEvent()->getOrder()->getStatusLabel();

}

}

You can use this code according to your need of getting order status anywhere inside custom development or custom extension.
Lastly, smash that stars if the code worked for you and don’t forget to comment down below if you are looking for any help regarding this code.
Happy Coding.

How to Get Order Status in sales_order_place_after event in Magento 2 2018-09-24T16:48:43+00:00 2019-02-12T15:47:05+00:00magecomp