Jigar KarangiyaJigar Karangiya

How to Change Order Status Programmatically in Magento 2

JK
Jigar Karangiya
· 1 min read

Hello Magento Devs,

All orders have an order status that is associated with a stage in the order processing workflow (opens in new tab).

In this tutorial we are going to see how we can change order status programatically instead of doing it manually.

php
$orderId = 11111; //your order id here
$objManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objManager->create('\Magento\Sales\Model\Order') ->load($orderId);
$newState = Order::STATE_PROCESSING;
$order->setState($newState)->setStatus(Order::STATE_PROCESSING);
$order->save();

Here are some default magento 2 order states which you can use in set Order State and Order Status:

States & StatusesValue
STATE_NEWnew
STATE_PENDING_PAYMENTpending_payment
STATE_PROCESSINGprocessing
STATE_COMPLETEcomplete
STATE_CLOSEDclosed
STATE_CANCELEDcanceled
STATE_HOLDEDholded
STATE_PAYMENT_REVIEWpayment_review
STATUS_FRAUD (Only Used for Order Status)fraud

That’s it.

You can read more about order status and states in magento 2 documantation page at Order Status (opens in new tab).

If you need help with this solution, feel free to ask in the Comments section below.

I would be happy to solve your queries.

(opens in new tab)

Written by Jigar Karangiya, Adobe Commerce & Magento 2 developer.

More about me

Related posts