You are here

function commerce_registration_delete_registrations in Commerce Registration 7.3

Same name and namespace in other branches
  1. 7.2 commerce_registration.rules.inc \commerce_registration_delete_registrations()

Action callback.

Deletes all registrations on a line item.

Related topics

File

./commerce_registration.rules.inc, line 330
Commerce Registration rules file.

Code

function commerce_registration_delete_registrations($line_item) {

  // Make sure the line item even has a registration product before continuing.
  if (!commerce_registration_line_item_is_registration($line_item)) {
    return;
  }
  $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
  $registrations = $line_item_wrapper->registrations
    ->value();
  if (!is_array($registrations)) {
    $registrations = unserialize($registrations);
  }
  $reg_ids = array();
  foreach ($registrations as $registration) {
    $reg_ids[] = $registration->registration_id;
  }
  registration_delete_multiple($reg_ids);
  $line_item_wrapper->registrations = array();
  $line_item_wrapper
    ->save();
}