Dear Stephen
Would it be possible to publish occurrences (in connection with their tickets) programmatically for event recurrence?
For example: Publish all occurrences of the following week on Sunday evening?
Thanks for looking into this.
Cheers, Benjamin.
Benjamin Ogg
Hi Benjamin,
You can’t publish an occurrences independently of the event. It should be possible to make bookings available only for occurrences in the coming week, however (albeit not through the UI) – is that what you’re trying to achieve?
Stephen Harris
Hi Stephen
Thanks for your answer and sorry for not being enough specific.
Lets say there is a yoga class every Monday at 9am. On every Sunday the occurrence can be viewed in the calendar and the booking for this occurrence is possible.
Would you execute this code as a paid job?
Happy Sunday, Benjamin
Benjamin Ogg
Hi Benjamin,
So the most straightforward way would be to create the event’s full occurrences and then hide occurrences that are more than X days away. Alternatively you could display the dates, but the make it unbookable until with X days.
Here’s how to do the former:
add_filter('pre_get_posts', function($query){
if( ! eventorganiser_is_event_query( $query, true ) ) {
return $query;
}
if (is_admin()) {
return $query;
}
if (!$query->get( 'event_start_before')){
$next_week = new DateTime( '+6 days', eo_get_blog_timezone() );
$query->set( 'event_start_before', $next_week->format('Y-m-d') );
}
}, 13);
Though currently it will still appear on the calendar. If your users will be logged-out you could do
if (is_admin() && !is_user_logged_in()) {
return $query;
}
Then it will be visible to users logged-in, but not to logged-out customers on the calendar.
To make just some occurrences bookable (but still dates still visible on calendars and lists), you can instead do:
add_filter( 'eventorganiser_bookable_occurrences', function( $bookable, $event_id ) {
$next_week = new DateTime( '+6 days', eo_get_blog_timezone() );
foreach( $bookable as $occurrence_id => $occurrence ) {
if ( $next_week > $occurrence['start'] ) {
unset( $bookable[$occurrence_id] );
}
}
return $occurrences;
}, 10, 2 );
Stephen Harris
Thanks for your support, Stephen. I highly appreciate this.
I will test your code and will let you know, how’s it going.
Cheers, Benjamin.
Benjamin Ogg
Dear Stephen
Please allow another question:
I am using shortcodes to display events [eo_fullcalender] and booking form [event_booking_form]
How can I integrate your code there accordingly?
Sorry, I am not that good in code… :o(
Cheers, Benjamin
Benjamin Ogg
Hi Benjamin,
Unfortunately that’s the limitation I referred to. It’ll still appear on the calendar, but you could hide them from non-logged-in users:
add_filter('pre_get_posts', function($query){
if( ! eventorganiser_is_event_query( $query, true ) ) {
return $query;
}
if (is_admin() && !is_user_logged_in()) {
return $query;
}
if (!$query->get( 'event_start_before')){
$next_week = new DateTime( '+6 days', eo_get_blog_timezone() );
$query->set( 'event_start_before', $next_week->format('Y-m-d') );
}
}, 13)
See this page on where to add the code: https://wp-event-organiser.com/blog/tutorial/where-should-i-put-code-from-the-tutorials/
Note, the calendar is cached so after making any code changes you may need to update an event to see any change.
Stephen Harris
Thanks a lot for your effort, Stephen.
I appreciate it a lot.
Benjamin Ogg