Skip to content

Instantly share code, notes, and snippets.

@Pebblo
Last active June 1, 2016 15:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pebblo/f89e3a7076acde7e7998 to your computer and use it in GitHub Desktop.
Save Pebblo/f89e3a7076acde7e7998 to your computer and use it in GitHub Desktop.
A [NEXT_UPCOMING_DATETIME_REG_VALUE] shortcode which counts all of the registrations for all tickets assigned to the next upcoming datetime within the event. By default the shortcode outputs the count of all 'Approved' registrations, you will need to pass the status you prefer to the shortcode such as RPP (Registration Pending Payment).
<?php
/*
Plugin Name: EE Site Specific Plugin
Description: Add custom functions for Event Espresso 4 here.
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */
//You can pass the status to the shortcode using [NEXT_UPCOMING_DATETIME_REG_VALUE status="{status}"]
//For example [NEXT_UPCOMING_DATETIME_REG_VALUE status="RPP"] for Pending Payment registrations.
function display_next_upcoming_datetime_reg_value( $attributes = array() )
{
//If this is being pulled by the Calendar, get out.
if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
{
return;
}
//Pull in all EE reg statuses
$reg_status_array = EEM_Registration::reg_status_array();
//Check the give status matches one of known statuses or is equal to 'all'.
if( (isset($attributes['status']) && $attributes['status'] != 'all') && !isset($reg_status_array[$attributes['status']])) {
//If the status does not match any known EE status, return invalid.
return __( 'Invalid status provided', 'event_espresso');
}
//set default attributes
$default_shortcode_attributes = array(
'status' => EEM_Registration::status_id_approved,
);
$attributes = array_merge( $default_shortcode_attributes, (array) $attributes );
//load helpers
EE_Registry::instance()->load_helper( 'Event_View' );
if ( empty( $attributes['event_id']) ) {
if ( is_single() && is_espresso_event() ) {
$event = EEH_Event_View::get_event();
}
} else {
$event = EEM_Event::instance()->get_one_by_ID( $attributes['event_id'] );
}
if( $event instanceof EE_Event) {
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $event->ID(), false, false, 1 );
$datetime = end($datetimes);
$tickets = $datetime->tickets();
$registration_count = 0;
foreach ( $tickets as $ticket) {
if( $attributes['status'] == 'all' ) {
$registration_count += $ticket->count_registrations( array( array( 'STS_ID' => array( '!=', EEM_Registration::status_id_incomplete ) ) ) );
} else {
$registration_count += $ticket->count_registrations( array( array( 'STS_ID' => array( '=', $attributes['status'] ) ) ) );
}
}
}
return $registration_count;
}
add_shortcode('NEXT_UPCOMING_DATETIME_REG_VALUE','display_next_upcoming_datetime_reg_value');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment