• Resolved dryan1144

    (@dryan1144)


    We have multiple events, and a user can buy a max of 1 ticket per event.

    We want to limit a user to only 1 event.

    Is there a way to accomplish this?

Viewing 5 replies - 16 through 20 (of 20 total)
  • Try testing using a non-admin user. Admins have special privileges that might make it difficult to test properly.

    The example FranceImage gave is just checking for a particular username and doesn’t include any code to prevent bookings. What you would need to do is write your own custom code to grab the username of the current logged in user and then check whether they’ve made previous bookings.

    Thread Starter dryan1144

    (@dryan1144)

    Update: Is there a way to test if a user has at least one booking that is NOT a cancelled booking? This is the key.

    Based on code from templates > my-bookings.php, there is a way to test if a user has a booking.

    global $wpdb, $current_user, $EM_Notices, $EM_Person;
    	if( is_user_logged_in() ):
    		$EM_Person = new EM_Person( get_current_user_id() );
    		$EM_Bookings = $EM_Person->get_bookings();
    		$bookings_count = count($EM_Bookings->bookings);
    		if($bookings_count > 0){
    			//Get events here in one query to speed things up
    			$event_ids = array();
    			foreach($EM_Bookings as $EM_Booking) {
    				$event_ids[] = $EM_Booking->event_id;
    			}
    		}

    You can then use ‘$bookings_count > 0’ or whatever you need to test whether a user has a booking.

    Another issue regarding cancellations comes up though. If a user cancels a booking they make through the My Bookings page, the system still counts this Cancelled booking as a booking. In other words, the $bookings_variable doesn’t go back to 0 if a user cancels a booking. It only goes to 0 when an admin deletes the booking completely through the admin.

    So again:
    Is there a way to test if a user has at least one booking that is NOT a cancelled booking? This is the key.

    Plugin Support angelo_nwl

    (@angelo_nwl)

    maybe you can use the above snippet (loop through $EM_Booking) and then check $EM_Booking->get_status() where Cancelled = 3

    I’m looking for a solution similar to this as well, where I can make sure they don’t try to book an event on the same day and time as one they are already booked to.

    Has anybody figured out how to throw up a warning that let’s them know they already have a booking pending/or booked when they attempt to book something during the same/date and time as the event they’re trying to book?

Viewing 5 replies - 16 through 20 (of 20 total)
  • The topic ‘Limit a user to one booking, globally’ is closed to new replies.