Set order status programmatically in magento 2

<?php
use Magento\Framework\App\Bootstrap;
use Magento\Sales\Model\Order;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$obj->get('\Magento\Framework\App\State')->setAreaCode('frontend'); // for remove Area code is not set error
$storeManager = $obj->get('\Magento\Store\Model\StoreManagerInterface');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$myString = '200003423';
$myArray = explode(',', $myString);
if ($myString) {
    foreach ($myArray as $value) {
        $order = $objectManager->create('\Magento\Sales\Model\Order')->loadByIncrementId($value);
        $orderState = Order::STATE_PROCESSING;
        $order->setState($orderState)->setStatus(Order::STATE_PROCESSING);
        $order->save();
        echo $value . ' => ' . $order->getStatus();
        echo '<br>';
    }die;
} else {
    echo 'Order id is empty please check into your admin panel';
}


Comments