function commerce_discount_commerce_cart_order_empty in Commerce Discount 7
Implements hook_commerce_cart_order_empty().
File
- ./
commerce_discount.module, line 156 - Defines the discount and discount offer entities, bundles and functionality.
Code
function commerce_discount_commerce_cart_order_empty($order) {
// Clean-up task to remove commerce_discount line items when cart is emptied.
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$line_items_to_delete = array();
foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {
if ($line_item_wrapper
->getBundle() == 'commerce_discount') {
$line_items_to_delete[] = $line_item_wrapper
->getIdentifier();
$order_wrapper->commerce_line_items
->offsetUnset($delta);
}
}
if ($line_items_to_delete) {
// Delete line items.
commerce_line_item_delete_multiple($line_items_to_delete);
}
}