{"id":882,"date":"2020-03-15T07:48:13","date_gmt":"2020-03-15T07:48:13","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2020\/03\/15\/get-current-order-status-and-new-order-status-in-magento-2\/"},"modified":"2025-05-22T14:44:35","modified_gmt":"2025-05-22T09:14:35","slug":"get-current-order-status-and-new-order-status-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-current-order-status-and-new-order-status-in-magento-2\/","title":{"rendered":"Expert Solution to Get Current Order Status And New Order Status in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Magento 2 is an insanely flexible platform that allows us, developers, to satisfy the crazy clients\u2019 requirements!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Isn\u2019t it?  <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I recently faced a similar situation where the client wanted to perform a specific action when the order status is changed. To do so, I had to&nbsp;<em><strong>get current order status and new order status in Magento 2<\/strong><\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this blog, I have posted that solution straightaway for the developers to save themselves from what I went through for the solution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can use the below code to implement, for example, a feature where a popup displays when the order state is changed from placed to processing saying that you can use this coupon code, or a feature to calculate and return tax amount when an order is placed and completed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Get the previous and next order status in Magento 2 to perform any action when the order status is changed, using the following code:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Get Current Order Status and New Order Status in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create&nbsp;<em><strong>di.xml<\/strong><\/em>&nbsp;file at&nbsp;<strong>app\/code\/Vendor\/Extension\/etc\/<\/strong>&nbsp;folder<\/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;type name=\"Magento\\Sales\\Model\\ResourceModel\\Order\">\n    &lt;plugin name=\"order_state_plugin\" type=\"Vendor\\Extension\\Plugin\\OrderPlugin\"\/>\n&lt;\/type><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create&nbsp;<em><strong>OrderPlugin.php<\/strong><\/em>&nbsp;file at&nbsp;<strong>app\/code\/Vendor\/Extension\/Plugin\/<\/strong><\/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\n\nnamespace Vendor\\Extension\\Plugin;\nuse Magento\\Sales\\Model\\ResourceModel\\Order;\nclass OrderPlugin\n{\n   public function afterSave(\n      Order $subject,\n      $result, $object\n   ) {\n      $oldData = $object->getOrigData('status');\n      $newData = $object->getData('status');\n      \\Magento\\Framework\\App\\ObjectManager::getInstance()->get('Psr\\Log\\LoggerInterface')->info(print_r(\"Old Data = $oldData\",true));\n      \\Magento\\Framework\\App\\ObjectManager::getInstance()->get('Psr\\Log\\LoggerInterface')->info(print_r(\"New Data = $newData\",true));\n   }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/make-order-status-visible-on-frontend-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">make order status visible on frontend in Magento 2<\/a>&nbsp;by tweaking the backend configuration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Learn here to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/get-order-status-label-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">get order status label in Magento 2<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do share the solution with fellow Magento developers via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Magento 2 is an insanely flexible platform that allows us, developers, to satisfy the crazy clients\u2019 requirements! Isn\u2019t it? I recently faced a similar situation&#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-882","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/882","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=882"}],"version-history":[{"count":3,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/882\/revisions"}],"predecessor-version":[{"id":15029,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/882\/revisions\/15029"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}