How to Get Order Status Label in Magento 2
The Magento 2 store admin can check the order status in the order view by navigating to Stores > Settings > Order Status grid.
The order status in any E-commerce store is an important metric based on which the admin needs to further act, be it offer the coupon code for next purchase, or mark the payment as complete, or upgrade the customer group after the order is complete.
Similarly, order status is important in Magento 2 store too and admin may often require the order status reference to carry out different functions.
Now apart from the default Magento 2 grids, the admin may want to display the order status labels in the custom grid or somewhere in the frontend for the customers’ reference.
Also, the admin may need to get order status label in Magento 2 while carrying out the order management. Furthermore, admin can also make order status visible to customers in Magento 2 and keep them updated with the same.
The order status label displays the current status of the particular customer’s order, and it changes according to the status of an order. i.e., Processing, Suspected Fraud, Pending Payment, On Hold e.t.c.
Follow the below code to get the order status label and use the solution wherever you want to display order status label.
Method to Get Order Status Label in Magento 2
Use the below code:
1 2 3 4 5 6 7 8 9 10 11 12 |
use \Magento\Sales\Model\OrderFactory; protected $orderFactory; public function __construct(\Magento\Sales\Model\OrderFactory $orderFactory) { $this->orderFactory = $orderFactory; } public function getOrderStatusLabel($orderId){ return $order = $this->orderFactory->create()->load($orderId)->getStatusLabel(); } |
That’s all! Now after done with getting order status label you can also change order status programmatically in Magento 2. For example, a custom order status “printed”. When the admin prints out the packing slip, the order status is changed to “printed”.
If you have any doubts regarding this post, just mention them in the Comments section below.
I would be happy to help.
Feel free to share the solution with Magento Community via social media.
Thank You.
Jignesh Parmar
An expert in his field, Jignesh is the team leader at Meetanshi and a certified Magento developer. His passion for Magento has inspired others in the team too. Apart from work, he is a cricket lover.
Prev
How to Use “checkout_type_multishipping_create_orders_single” Event in Magento 2
How to Get All Orders of Customer by Email ID in Magento 2
Next