Hello Magento Devs,
All orders have an order status that is associated with a stage in the order processing workflow.
In this tutorial we are going to see how we can change order status programatically instead of doing it manually.
$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 & Statuses | Value |
STATE_NEW | new |
STATE_PENDING_PAYMENT | pending_payment |
STATE_PROCESSING | processing |
STATE_COMPLETE | complete |
STATE_CLOSED | closed |
STATE_CANCELED | canceled |
STATE_HOLDED | holded |
STATE_PAYMENT_REVIEW | payment_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.
If you need help with this solution, feel free to ask in the Comments section below.
I would be happy to solve your queries.
Leave a Comment