Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active July 18, 2020 00:27
Show Gist options
  • Save spivurno/7858140 to your computer and use it in GitHub Desktop.
Save spivurno/7858140 to your computer and use it in GitHub Desktop.
Gravity Perks // GP Limit Choices // Display Spots Left in Choice Labels
<?php
/**
* Display how many spots are left in the choice label when using the GP Limit Choices perk
* http://gravitywiz.com/gravity-perks/
*/
add_filter( 'gplc_remove_choices', '__return_false' );
add_filter( 'gplc_pre_render_choice', 'my_add_how_many_left_message', 10, 5 );
function my_add_how_many_left_message( $choice, $exceeded_limit, $field, $form, $count ) {
$limit = rgar( $choice, 'limit' );
$how_many_left = max( $limit - $count, 0 );
$message = "($how_many_left spots left)";
$choice['text'] = $choice['text'] . " $message";
return $choice;
}
@mike-weiner
Copy link

@spivurno Thanks for the quick response! That is much easier!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment