You are here

function commerce_coupon_code_is_in_order in Commerce Coupon 7

Finds out if a given coupon code is present in an order.

Parameters

$code: Coupon code to check.

$order: Commerce order object.

Return value

boolean Returns TRUE if the coupon is in the order, otherwise return FALSE.

1 call to commerce_coupon_code_is_in_order()
commerce_coupon_code_is_valid in ./commerce_coupon.module
Checks if a given coupon is valid for a given order. The validation is done by the rules engine.

File

./commerce_coupon.module, line 818
Coupon System for Drupal Commerce.

Code

function commerce_coupon_code_is_in_order($code, $order) {
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  foreach ($order_wrapper->commerce_coupon_order_reference as $coupon_wrapper) {
    if (strcasecmp($coupon_wrapper->commerce_coupon_code
      ->raw(), $code) == 0) {
      return TRUE;
    }
  }
  return FALSE;
}