forked from gravitywiz/snippet-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gplc-spots-left-plus-waiting-list.php
31 lines (28 loc) · 1.22 KB
/
gplc-spots-left-plus-waiting-list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* Gravity Perks // GP Limit Choices // Spots Left + Waiting List Message
*
* Display the number of spots left in the label of each choice. If there are no spots left, it will display a waiting list message.
* https://gravitywiz.com/documentation/gravity-forms-limit-choices/
*
* Plugin Name: GP Limit Choices — Spots Left + Waiting List Message
* Plugin URI: https://gravitywiz.com/documentation/gravity-forms-limit-choices/
* Description: Display the number of spots left in the label of each choice. If there are no spots left, it will display a waiting list message.
* Author: Gravity Wiz
* Version: 0.1
* Author URI: https://gravitywiz.com
*/
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, 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 );
if ( $how_many_left <= 0 ) {
$message = '(waiting list)';
} else {
$message = "($how_many_left spots left)";
}
$choice['text'] = $choice['text'] . " $message";
return $choice;
}