You are here

function commerce_shipping_rules_line_item_exists in Commerce Shipping 7.2

Checks an order for the existence of a shipping line item.

Parameters

object $order: The order to check for a shipping line item.

string $service: The machine-name of a particular shipping service to search for; if '-any-' the condition returns TRUE for any found shipping line item.

1 string reference to 'commerce_shipping_rules_line_item_exists'
commerce_shipping_rules_condition_info in ./commerce_shipping.rules.inc
Implements hook_rules_condition_info().

File

./commerce_shipping.rules.inc, line 99
Rules integration for shipping.

Code

function commerce_shipping_rules_line_item_exists($order, $service) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

  // Loop over all the line items on the order.
  foreach ($order_wrapper->commerce_line_items as $delta => $line_item_wrapper) {

    // If the current line item is a shipping line item and the condition either
    // doesn't care about the service or the service name matches, return TRUE.
    if ($line_item_wrapper->type
      ->value() == 'shipping' && ($service == '-any-' || $line_item_wrapper->commerce_shipping_service
      ->value() == $service)) {
      return TRUE;
    }
  }
  return FALSE;
}