How to add Status History Comment to the order by id in Magento 2?

You can add Status History Comment for the given order programmatically in Magento 2.

You need to use interface, Magento\Sales\Api\OrderStatusHistoryRepositoryInterface to add a comment. You can also set order status for the comment.

You can check to add sales order status history data programmatically in Magento 2.

You have to Retrieve the Order id to add comment, load order object by the id, add status history comment for the given sales order with some code snippet,

You can pass order status for the comment if you want using the second parameter in addStatusHistoryComment($message, $status) method.

Call method with a required parameter,


order status History Comment
order status History Comment Magento 2