$orderId = $orderIds[0];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order') ->load($orderId);
$order->setState(\Magento\Sales\Model\Order::STATE_COMPLETE, true);
$order->setStatus(\Magento\Sales\Model\Order::awaiting_stock );
$order->addStatusToHistory($order->getStatus(), 'Awaiting Stock');

This is my code and I want to set there custom status. How can I set there custom status?


If you want to create a custom order status you need to go to the backend under Stores > Settings > Order Status and create a new status. Take good note of the status code you're using here.

Once you've created it, you need to assign it to a state (in your case I assume this is the "complete" state according to your code.

Then you can tweak your code with:


Where "custom_status_code" is the status code you used when creating your custom status.

| improve this answer | |
  • thanks for reply @Raphael at Digital Pianism .I want change order status Pending To Custom Status when order placed can you tell me How i do that ? – Rahul Katoch Mar 28 '17 at 10:33
  • Once payment is done, the order status showing as "Processing" by default but I wanted to show as "Pending/New" similar to "Cash On Delivery". If I want to set the order status as "Pending/New" programmatically once the order is placed. What should I do? Please advise. – Vinayagam Jan 14 at 15:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.