function hook_uc_coupon_apply in Ubercart Discount Coupons 7.2
Same name and namespace in other branches
- 7.3 uc_coupon.api.php \hook_uc_coupon_apply()
Invoked whenever a valid coupon is applied to an order. May be invoked than once for the same coupon if it becomes invalid due to change in cart contents.
Note that you should not do anything in your hoook implementation which causes the current cart contents to be rebuilt. This includes calls to uc_cart_add_item() without explicitly setting the $rebuild argument to false. And, since coupons may be submitted on the checkout page after the cart contents are frozen, updates to the cart contents may fail under some circumstances anyway.
Parameters
$coupon: The fully validated coupon which was applied.
1 function implements hook_uc_coupon_apply()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- uc_coupon_workflow_uc_coupon_apply in uc_coupon_workflow/
uc_coupon_workflow.module - Implements hook_uc_coupon_apply().
1 invocation of hook_uc_coupon_apply()
- uc_coupon_session_validate in ./
uc_coupon.module - Validates all coupons in the current session. The validated coupons are statically cached for each request. The cache is rebuilt the first time this function is called, or every time the cart contents are rebuilt.
File
- ./
uc_coupon.api.php, line 174 - Ubercart Discount Coupon module api/hooks. Version 7.x-2.x
Code
function hook_uc_coupon_apply($coupon) {
// Grant a role to the active user when a particular coupon is applied.
// This could be used in conjunction with a node access module to expose products
// only when certain coupon codes are entered.
global $user;
if ($coupon->cid == 99 && $user->uid != 0) {
$roles = $user->roles + array(
99 => 'My Special Role',
);
user_save($user, array(
'roles' => $roles,
));
}
}