Last active
April 5, 2018 13:09
-
-
Save joshfeck/c7fb0043e2bbe9bb3619 to your computer and use it in GitHub Desktop.
The first example below will print a list of the available spaces for each datetime, located after the ticket selector. The second example will add a "spaces left" item next to each datetime listed for the event. Requires Event Espresso 4.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
// print the remaining tickets left for each datetime | |
add_action( 'AHEE__ticket_selector_chart__template__after_ticket_selector', 'ee_print_tickets_left_after_selector', 10, 2 ); | |
function ee_print_tickets_left_after_selector( $EVT_ID, $event ) { | |
echo '<ul style="margin-left:0;">'; | |
$datetimes = $event->datetimes(); | |
foreach($datetimes as $datetime){ | |
if ( $datetime instanceof EE_Datetime ) { | |
$dtt_name = $datetime->get('DTT_name'); | |
$name = !empty($dtt_name) ? ($datetime->name()) : 'this event'; | |
$limit = $datetime->get('DTT_reg_limit'); | |
$remain = $datetime->spaces_remaining( true ); | |
$remain = $limit == EE_INF ? 'a lot of' : $remain; | |
if ( $datetime->sold_out() ) { | |
echo $name . ' is <b>sold out</b>'; | |
} else { | |
printf( _nx( | |
'%1$sThere is one space left for %3$s', | |
'%1$sThere are %2$s spaces left for %3$s', | |
$remain, 'event ticket info', 'event_espresso' ), | |
'<li style="list-style-type:none;">', $remain, '<span>' . $name . '</span></li>' | |
); | |
} | |
} | |
} | |
echo '</ul>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file | |
add_filter( | |
'FHEE__espresso_list_of_event_dates__datetime_html', | |
'ee_print_avaialble_datetime_reg_limit', | |
20, | |
2 | |
); | |
function ee_print_avaialble_datetime_reg_limit($html, $datetime){ | |
$remain = $datetime->spaces_remaining( true ); | |
$remain = $remain == EE_INF ? '' : $remain . ' left'; | |
$html = $html . '<span class="ee-remaining-date">'.$remain.'</span>'; | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment