🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Change Order Status Programmatically in Magento 2

By Sanjay JethvaUpdated on May 22, 2025 1 min read

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.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.