Hi there, we want to limit the number of times a coupon code is used. Is there a way to have this functionality? Currently a coupon can used as many times as needed.
If this not possible today, how can I build this? I did see that the coupon code is being tracked in the events_attendee table as a column called coupon_code. Is there function I can build that injected at the time when the Total is being refreshed? How would I go about that?
I have prepared a function that deletes a coupon code from the system once it is used. This function needs to be put in the functions.php file and can be called once the event registration page is loaded. This is not a full proof solution, but it gets what I want to get done.
function deleteUsedCouponCodes() {
global $wpdb;
$discountcode = $wpdb->get_results( "SELECT coupon_code FROM hff_events_discount_codes", ARRAY_A );
foreach ( $discountcode as $code )
{
$couponcode = $code['coupon_code'];
$usedcode = $wpdb->get_var( "SELECT COUNT(*) FROM hff_events_attendee WHERE coupon_code = '$couponcode'" );
if ($usedcode > 0) { //THE CODE HAS ALREADY BEEN USED, LET'S DELETE IT.
$wpdb->query( "DELETE FROM hff_events_discount_codes WHERE coupon_code = '$couponcode'" );
}
}
return false;
}
Viewing 1 reply thread
The support post ‘Limit the number of times a coupon code is used’ is closed to new replies.
Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.
Support forum for Event Espresso 3 and Event Espresso 4.