{"id":1423,"date":"2020-12-07T17:39:57","date_gmt":"2020-12-07T17:39:57","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/change-order-status-programmatically-in-magento-2\/"},"modified":"2025-05-22T11:23:06","modified_gmt":"2025-05-22T05:53:06","slug":"change-order-status-programmatically-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/change-order-status-programmatically-in-magento-2\/","title":{"rendered":"How to Change Order Status Programmatically in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Magento 2 orders have an&nbsp;<a href=\"https:\/\/experienceleague.adobe.com\/en\/docs\/commerce-admin\/stores-sales\/guide-overview\" target=\"_blank\" rel=\"noreferrer noopener\">order status<\/a>&nbsp;that is linked with a state in the order processing flow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One can&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/create-magento-2-order-status-order-state\/\" target=\"_blank\" rel=\"noreferrer noopener\">create custom order status in Magento 2<\/a>&nbsp;if required.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, a custom order status \u201cprinted\u201d. When the admin prints out the packing slip, the order status is changed to \u201cprinted\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Instead of doing it manually, one can&nbsp;<em><strong>change order status programmatically in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method to Change Order Status Programmatically in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the code given below, change status in&nbsp;<strong>\u201cStatus Code\u201d&nbsp;<\/strong>as per your business requirements.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nuse Magento\\Sales\\Model\\Order;\nprotected $order;\npublic function __construct(Order $order)\n{\n    $this->order = $order;\n}\npublic function orderStatusChange()\n{\n    $orderId = 9999;\n    $order = $this->order->load($orderId);\n    $order->setStatus(\"Status Code\");\n    $order->save();\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Please do consider sharing this post to Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Magento 2 orders have an&nbsp;order status&nbsp;that is linked with a state in the order processing flow. One can&nbsp;create custom order status in Magento 2&nbsp;if&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-1423","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1423"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1423\/revisions"}],"predecessor-version":[{"id":14588,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1423\/revisions\/14588"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}