Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spivurno/82092c812c49891670dc to your computer and use it in GitHub Desktop.
Save spivurno/82092c812c49891670dc to your computer and use it in GitHub Desktop.
Gravity Perks // GP Limit Choices // Spots Left + Waiting List Message
/**
* Gravity Perks // GP Limit Choices // Spots Left + Waiting List Message
*
* Allows you to display the number of spots left in the label of each choice. If there are no spots left, will display a waiting list message.
*
* @link http://gravitywiz.com/documentation/gp-limit-choices/
*/
add_filter( 'gplc_remove_choices', '__return_false' );
add_filter( 'gplc_disable_choices', '__return_false' );
add_filter( 'gplc_pre_render_choice', 'my_add_how_many_left_message', 10, 4 );
function my_add_how_many_left_message( $choice, $exceeded_limit, $field, $form ) {
$choice_counts = GWLimitChoices::get_choice_counts( $form['id'], $field );
$count = intval( rgar( $choice_counts, $choice['value'] ) );
$limit = rgar( $choice, 'limit' );
$how_many_left = max( $limit - $count, 0 );
if( $how_many_left <= 0 ) {
$message = '(waiting list)';
} else {
$message = "($how_many_left spots left)";
}
$choice['text'] = $choice['text'] . " $message";
return $choice;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment