Created
July 22, 2019 00:59
-
-
Save CameronGilroy/f3a3c2aa3445715a46c6fbc7a4814c78 to your computer and use it in GitHub Desktop.
Display how many spots are left in the choice label when using the GP Limit Choices perk
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 | |
/** | |
* Display how many spots are left in the choice label when using the GP Limit Choices perk | |
* https://gravitywiz.com/gravity-perks/ | |
*/ | |
add_filter( 'gplc_remove_choices', '__return_false' ); | |
add_filter( 'gplc_pre_render_choice', 'ayc_add_how_many_left_message', 10, 5 ); | |
function ayc_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; | |
} | |
add_filter( 'gplc_remove_choices', '__return_false' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment