Created
October 31, 2019 17:16
-
-
Save cgi-caesar/fbdd2a2b362d8d659046944962d425c3 to your computer and use it in GitHub Desktop.
aMember (site.php): Limit usage of coupon by IP address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Am_Di::getInstance()->hook->add(Am_Event::VALIDATE_COUPON, function(Am_Event $e) { | |
$batch = $e->getCouponBatch(); | |
$coupon = $e->getCoupon(); | |
$used = $e->getDi()->invoiceTable->countBy([ | |
'coupon_id' => $coupon->pk(), | |
'remote_addr' => $_SERVER['REMOTE_ADDR'] | |
]); | |
if ($used >= $batch->user_use_count) { | |
$e->addReturn(___('Coupon usage limit exceeded')); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment