Hey Stephen,
is there a way to change bookings so that users can book until the very last day of the event? I.E. if the event data range is 5/19 – 5/23 users can not book on those days, though I would like them to be able to book all the way until 5/23.
Gabriel David
Hi Gabriel,
I take that this isn’t a recurring event, but instead a single ‘long’ event? Unfortunately, when the requirement that a bookable occurrence can’t yet have occurred is fairly hardcoded. Specifically line 335 of includes/booking-tickets.php
//Sanity check: If the event has no future occurrences, no tickets will be available.
if ( ! $occurrences = eo_get_the_future_occurrences_of( $post_id ) )
return false;
Of course that can changed to allow all dates (which probably isn’t desirable );
if ( ! $occurrences = eo_get_the_occurrences_of( $post_id ) )
return false;
Alternatively you could define your own function which returns only occurrences which have not yet finished. Here, each occurrence is an array with keys ‘start’ and ‘end’ with DateTime object values. The array of occurrences is indexed by the occurrence ID. (See codex for eo_get_the_occurrences_of()
for details).
At this point, you cannot avoid editing the core plug-in as there is no suitable filter for altering which occurrences for a given event are ‘bookable’. I’ll looking at extracting that out into its own function and providing a filter in 1.8. This won’t necessary be the final result, but it may be something like:
/**
* (Provisional: may be added in 1.8)
* Returns an array of occurrence IDs of the event which are 'bookable' (even if they are fully booked).
*/
function eo_get_bookable_occurrence_ids( $event_id ){
$occurrence_ids = ... //retrieve 'future' occurence IDs
return apply_filters( 'eventorganiser_bookable_occurrences', $occurrence_ids, $event_id );
}
You could then do the following:
/**
* Function that can be added in third-party plug-in to alter which dates for an event are bookable.
*/
function gabriel_make_running_occurrences_bookable( $occurrence_ids, $event_id ){
$occurrence_ids = ... //alter/replace $occurrence_ids so it includes occurrences that have started, but not finished
return $occurrence_ids;
}
add_filter( 'eventorganiser_bookable_occurrences', 'gabriel_make_running_occurrences_bookable', 10, 2 );
Stephen Harris
Thank you Stephen, helpful as always!
Gabriel David
So I tried adding a custom function to output a boolean based on if the final day of the event is over, as follow:
function god_is_event_over($e_id){
$occurrences = eo_get_the_occurrences_of($e_id);
$currentDate = date("Y-m-d");
$currentTime = date("H:i:s");
$currentDate = strtotime($currentDate . $currentTime);
foreach($occurrences as $oc):
if($oc["end"]->getTimestamp() < $currentDate){
return true;
}
endforeach;
return false;
}
and I changed the line in includes/booking-tickets.php (335) to the following:
if ( god_is_event_over( $post_id ) )
return false;
But the booking form still says Booking are no Longer Available. I did a bit of debugging, and it seems the cause is somewhere between line 338 and 362, but there is nothing returning false in that range. What else would be telling EO that there are no tickets available?
Gabriel David
I still need help with this please Stephen, when you get a chance 🙁
Gabriel David
Hi Gabriel,
The comment in line 335. It’s purpose is not just to “check if the event has no future occurrences, no tickets will be available” but also to populate an array of occurrences ($occurrences
) which may have tickets. Specifically the function is tasked with checking the availability of the specified occurrences. The above check, populates $occurrences
with future occurrences to whitelist future occurrences.
I would recommend something like:
$occurrences = eo_get_the_occurrences_of( $post_id );
$now = new DateTime( 'now', eo_get_blog_timezone() );
foreach( $occurrences as $occurrence_id => $occurrence ){
//If end date has passed - remove it
if( $occurrence['end'] < $now ){
unset( occurrences[$occurrence_id] );
}
}
Stephen Harris