Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenharris/26d82a2d7537f9840f5c to your computer and use it in GitHub Desktop.
Save stephenharris/26d82a2d7537f9840f5c to your computer and use it in GitHub Desktop.
This plug-in marks events which are fully booked as red in the fullCalendar and removes the link to the event.
<?php
/*
* Plugin Name: Event Organiser Calendar Booked Event Highlight
* Version: 1.0
* License: GNU General Public License, v2 (or newer)
* License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/**
* This plug-in marks events which are fully booked as red in the fullCalendar
* and removes the link to the event.
*
* To use this place this file inside your plug-ins repository and then activate the plug-in
* "Event Organiser Calendar Booked Event Highlight"
*
**/
/**
* Changes the event colour, text colour and removes the link (if the event is fully booked)
*/
function my_mark_event_as_booked( $event, $event_id, $occurrence_id ){
//Check if the event has tickets
if( eo_get_event_tickets( $event_id ) ){
//Check if the event has any tickets remaining
if( eventorganiser_pro_get_option( 'book_series' ) ){
$remaining = eo_get_remaining_tickets_count( $event_id );
}else{
$remaining = eo_get_remaining_tickets_count( $event_id, $occurrence_id );
}
//If not change colour and url
if( 0 == $remaining ){
//Change event color to red
$event['color'] = '#ff0000';
$event['textColor'] = '#000000';
$event['url'] = false; //remove link (optional!)
$event['title'] = $event['title'] . " (Fully booked)"; //change title (optional!)
$event['description'] = "<strong>Fully booked.</strong> <br>" . $event['description']; //change tooltip content (optional!)
}
}
return $event;
}
add_filter( 'eventorganiser_fullcalendar_event', 'my_mark_event_as_booked', 10, 3 );
/**
* Because the calendar is cached, we need to clear it whenever a booking is confirmed.
*/
function my_clear_calendar_cache( $booking_id ){
delete_transient( 'eo_full_calendar_public' );
delete_transient( 'eo_full_calendar_public_priv' );
}
add_action( 'eventorganiser_confirmed_booking', 'my_clear_calendar_cache' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment