You are here

function hook_uc_coupon_usage_alter in Ubercart Discount Coupons 7.3

Same name and namespace in other branches
  1. 6 uc_coupon.api.php \hook_uc_coupon_usage_alter()
  2. 7.2 uc_coupon.api.php \hook_uc_coupon_usage_alter()

hook_uc_coupon_usage_alter().

Allow modules to alter the usage count for a coupon.

Parameters

$usage: An associative array consiting of the following keys: - 'user' => The number of times this coupon has been used by the specified user. - 'codes' => An associative array listing the total number of uses for each code (for all users).

$cid: The coupon-id of the coupon in question.

$uid: The user-id whose usage is to be checked.

1 invocation of hook_uc_coupon_usage_alter()
uc_coupon_count_usage in ./uc_coupon.module
Count usage of a coupon.

File

./uc_coupon.api.php, line 23
Ubercart Discount Coupon module api/hooks. Version 7.x-2.x

Code

function hook_uc_coupon_usage_alter(&$usage, $cid, $uid) {

  // See if this coupon has been used in our table.
  $rows = db_query('SELECT code, uses FROM {extra_coupon_usage} WHERE cid = :cid', array(
    ':cid' => $cid,
  ));
  foreach ($rows as $row) {
    if (isset($usage[$row->code])) {
      $usage[$row->code] += $row->uses;
    }
    else {
      $usage[$row->code] = $row->uses;
    }
  }
}