Hi Stephen.
Is it possible to not allow bookings that fall into the same time spot ?
for example: Concert – 8-9pm (free) Concert 2 8-9pm (free)
At this stage if I use the example above my users can book for both events even though they overlap. Doesn’t really help the attendance figures (we have limited spaces) if a user gets greedy and just books them all
My users have to be logged in to book.
Thanks Stephen
Jody

Jody Brown
Hi Jody,
This is possible. On the booking form validation hook (eventorganiser_validate_booking_form_submission
) you can do one of two things:
- Look up events this user is attending and check the dates don’t overlap
- Look up all concurrent events and check that the user has not booked for any of them.
The only difference will a slight performance gain depending on whether you have a lot concurrent events or potentially users booking a lot of events. The latter is probably more likely, so below that’s what I’ve gone with. It requires Pro 1.7+ because of the newer hook used (there is another deprecated one used in old versions).
function my_check_bookings_dont_clash( $form ){
$event_id = (int) $form->get( 'event_id' );
//I'm assuming you're booking by date too
$occurrence_id = (int) $form->get( 'occurrence_id' );
$event_starts = eo_get_the_start( DATETIMEOBJ, $event_id, null, $occurrence_id );
$event_ends = eo_get_the_end( DATETIMEOBJ, $event_id, null, $occurrence_id );
//Find all concurrent events
$events = eo_get_events( array(
'event_start_before' => $event_ends,
'event_end_after' => $event_starts,
));
if( $events ){
//Get all statuses except 'cancelled'. You may want to change this if you want to ignore 'pending' bookings as well.
$statuses = eo_get_booking_statuses( array( 'name' => 'cancelled' ), 'names', 'not' );
$user_id = get_current_user_id();
foreach( $events as $event ){
if( eo_user_has_bookings( $user_id, $event->ID, $event->occurrence_id, $statuses ){
$form->add_error(
'booking-clash',
sprintf( 'Sorry you\'re already attending "%s" at that time.', get_the_title( $event->ID ) )
);
}
}
}
}
add_action( 'eventorganiser_validate_booking_form_submission', 'my_check_bookings_dont_clash', 15 );
This hasn’t been untested, so there maybe a few typos.
Remarks
- You can change the statuses which are checked. In the above we check
if the user has any bookings for any concurrent event which is not cancelled.
- It doesn’t ignore the current event being booked. If you want the user to be able to make an additional booking for the same
event, you’ll want to skip where the concurrent event is the same as
the current event being booked

Stephen Harris
Thanks Stephen
Where should this code go ?
If one event finishes at 9pm and the next event starts at 9pm will this be an issue ?

Jody Brown
Where should this code go ?
Ideally, its own dedicated plug-in or a site utility function. It will work in your theme’s functions.php
but this adds hassle when switching theme.
If one event finishes at 9pm and the next event starts at 9pm will this be an issue ?
Yes. You can work around this by doing
$event_starts = clone eo_get_the_start( DATETIMEOBJ, $event_id, null, $occurrence_id );
$event_ends = clone eo_get_the_end( DATETIMEOBJ, $event_id, null, $occurrence_id );
$event_starts->modify( '+1 second' );
$event_ends->modify( '-1 second' );
The clone
s are important.

Stephen Harris
Hi Stephen
sent email regards freelance to implement this.

Jody Brown