The crazily adaptable Magento 2 platform enables us, as developers, to meet the demanding client demands!
Is it not?
The client wanted to do a particular action when the order status changed, and I recently encountered a situation similar to this. I needed to retrieve the most recent order status and the old order status in Magento 2.
I immediately put that solution in this blog so that the developers wouldn't have to go through what I did to find the answer.
The code provided below can be used to add features such as those that notify customers to utilize a coupon code when their order status changes from place to processing or that compute and refund tax when an order is placed and completed.
To take any action when the order status changes in Magento 2, get the prior and subsequent order status using the shared code.
Visit: https://meetanshi.com/blog/get-current-order-status-and-new-order-status-in-magento-2/