function hook_commerce_order_can_delete in Commerce Core 7
Lets modules prevent the deletion of a particular order.
Before an order can be deleted, other modules are given the chance to say whether or not the action should be allowed. Modules implementing this hook can check for reference data or any other reason to prevent an order from being deleted and return FALSE to prevent the action.
This is an API level hook, so implementations should not display any messages to the user (although logging to the watchdog is fine).
Parameters
$order: The order to be deleted.
Return value
bool TRUE or FALSE indicating whether or not the given order can be deleted.
1 invocation of hook_commerce_order_can_delete()
- CommerceOrderEntityController::delete in modules/
order/ includes/ commerce_order.controller.inc - Deletes multiple orders by ID.
File
- modules/
order/ commerce_order.api.php, line 213 - Hooks provided by the Order module.
Code
function hook_commerce_order_can_delete($order) {
// Use EntityFieldQuery to look for payment transactions referencing this
// order, and do not allow the delete to occur if one or more exist.
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_payment_transaction', '=')
->propertyCondition('order_id', $order->order_id, '=')
->count();
return $query
->execute() == 0;
}