commerce_order_status_update
| DC commerce_order.module | commerce_order_status_update($order, $name, $skip_save = FALSE, $revision = TRUE, $log = '') |
Updates the status of an order to the specified status.
While there is no explicit Rules event or hook devoted to an order status being updated, you can use the commerce_order_updated event / hook to check for a changed order status by comparing $order->original->status to the $order->status. If they are different, this will alert you that the order status for the given order was just changed.
Parameters
$order: The fully loaded order object to update.
$name: The machine readable name string of the status to update to.
$skip_save: TRUE to skip saving the order after updating the status; used when the order would be saved elsewhere after the update.
$revision: TRUE or FALSE indicating whether or not a new revision should be created for the order if it is saved as part of the status update. Defaults to TRUE.
$log: If a new revision is created for the update, the log message that will be used for the revision.
Return value
The updated order.
File
- sites/
all/ modules/ commerce/ modules/ order/ commerce_order.module, line 1275 - Defines the core Commerce order entity and API functions to manage orders and interact with them.
Code
<?php
function commerce_order_status_update($order, $name, $skip_save = FALSE, $revision = TRUE, $log = '') {
// Do not update the status if the order is already at it.
if ($order->status != $name) {
$order->status = $name;
if (!$skip_save) {
// If the status update should create a new revision, update the order
// object to reflect this and include a log message.
if ($revision) {
$order->revision = TRUE;
$order->log = $log;
}
commerce_order_save($order);
}
}
return $order;
}
?> 