The Magento 2 orders have an order status that is linked with a state in the order processing flow.
One can create custom order status in Magento 2 if required.
For example, a custom order status “printed”. When the admin prints out the packing slip, the order status is changed to “printed”.
Instead of doing it manually, one can change order status programmatically in Magento 2.
Method to Change Order Status Programmatically in Magento 2
In the code given below, change status in “Status Code” as per your business requirements.
<?php use Magento\Sales\Model\Order; protected $order; public function __construct(Order $order) { $this->order = $order; } public function orderStatusChange() { $orderId = 9999; $order = $this->order->load($orderId); $order->setStatus("Status Code"); $order->save(); }
That’s it.
Please do consider sharing this post to Magento Community via social media.
Thank you.