How to change programmatically order status and add comment in history in magento?

Programmatically change order status and add comment in history in Magento.




<?php

 $orderId = 100000821; // you're order Id
$order = Mage::getModel('sales/order')->load(orderId );
$order->addStatusToHistory($order->getStatus(), 'Put your comment here', false);
                     OR
$order->addStatusToHistory('complete', 'Put your comment here', false);
/* 1st parameter is status,
2nd is comments,
3rd is notified customer. */

$order->save();

Note:- if you want to display status on front end than change this

 $order->addStatusToHistory($order->getStatus(), 'Put your comment here', false)->setIsVisibleOnFront(1); // customer can see new status
?>

Leave a Reply