How To Add Comments Programmatically For Magento 2 Order

I am writing a small extension, if have an order id, how to add comments to the Magento 2 order programmtically
You need to load Magento 2 order by order id first and then call method – addStatusHistoryComment to assign the comments to the Magento 2 order.
$orderId = 1;
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('\Magento\Sales\Model\Order')->load($orderId);
$order->addStatusHistoryComment('Test test');
$order->save();
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments