Forked from spivurno/gp-limit-choices-spots-left-plus-waiting-list.php
Created
September 5, 2016 04:50
-
-
Save phillipwilhelm/302b32c23d8a9f218c01a9cd29b0cd40 to your computer and use it in GitHub Desktop.
Gravity Perks // GP Limit Choices // Spots Left + Waiting List Message
This file contains hidden or 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