3

This question already has an answer here:

$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');
$order->save();

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

marked as duplicate by Raphael at Digital Pianism magento2 Mar 28 '17 at 10:26

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

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:

$order->setStatus("custom_status_code");

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

  • 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

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