Support

Home Forums Event Espresso Premium Limit the number of times a coupon code is used

Limit the number of times a coupon code is used

Posted: May 2, 2014 at 9:13 am

Viewing 1 reply thread


Sulayman Khan

May 2, 2014 at 9:13 am

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?


Lorenzo Orlando Caum

  • Support Staff

May 2, 2014 at 10:57 am

Hello,

This will take custom coding to accomplish. Please get in touch with an Event Espresso professional here:

https://eventespresso.com/developers/event-espresso-pros/


Lorenzo


Sulayman Khan

May 2, 2014 at 5:21 pm

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.

Event Espresso