function commerce_discount_usage_max_usage_per_person in Commerce Discount 7
Rules condition callback: evaluate maximum usage per-person of a discount.
1 string reference to 'commerce_discount_usage_max_usage_per_person'
File
- ./
commerce_discount.rules.inc, line 1531 - Rules integration for the Commerce Discount module.
Code
function commerce_discount_usage_max_usage_per_person($order, $discount_name) {
if (!($discount = entity_load_single('commerce_discount', $discount_name))) {
return FALSE;
}
$per_person_limit = FALSE;
// Don't use the wrapper getter on purpose for performance reasons.
if (isset($discount->discount_usage_per_person[LANGUAGE_NONE])) {
$per_person_limit = $discount->discount_usage_per_person[LANGUAGE_NONE][0]['value'];
}
// Nothing to count if the order does not have an email.
if (!$per_person_limit || !$order->mail) {
return TRUE;
}
// Find other orders owned by same person that have same discount.
$usage = commerce_discount_usage_get_usage_by_mail($discount_name, $order->mail, $order->order_id);
return $usage < $per_person_limit;
}