Created
August 10, 2014 21:19
-
-
Save spivurno/82092c812c49891670dc to your computer and use it in GitHub Desktop.
Gravity Perks // GP Limit Choices // Spots Left + Waiting List Message
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
/** | |
* 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
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gp-limit-choices/gplc-spots-left-plus-waiting-list.php