GRAVITY PERKS LIMIT CHOICES
What does it do?
GP Limit Choices is a Gravity Forms plugin that allows you to limit how many times each “choice” on a multi-choice field may be selected (e.g. Radio Buttons, Checkboxes, Drop Downs, etc). It works with Product and Options fields with these input types as well.
GRAVITY PERKS LIMIT CHOICES
How does it work?
This perk enables you to specify a limit per choice on your multi-choice field. If a choice reaches its specified limit it will no longer appear in the field on the front-end. While the choice is visually removed from the frontend, it is still editable via the Form Editor so the limit may be adjusted.Disable Exhausted Choices Rather than Remove
GRAVITY PERKS LIMIT CHOICES
If you would like to disable rather than remove exhausted choices, just add this code to your theme’s functions.php file:
add_filter( 'gplc_remove_choices', '__return_false' );
How do I enable this functionality?
Navigate to an existing form or create a new form with a multi-choice field. Open the field’s settings and look for the checkbox labeled “enable limits” above the “Choices” section and next to the “enable values” option. Check the “enable limits” option to reveal a new “Limit” column for the “Choices” section.GRAVITY PERKS LIMIT CHOICES
For each choice, specify a limit (as an integer) for how many times that choice should be able to be selected. Leave the limit blank for choices with no limit.Limit Choices SettingsIf a limit is applied to choices in a Product or Option field and there is a Quantity field associated with that Product field, the quantity ordered will be counted towards the limit.GRAVITY PERKS LIMIT CHOICES
Filters
Display Spots Left Label
This will give you the option to display how many spots are left in the choice label when using the Gravity Forms Limit Choices perk.
<?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; | |
} |
view rawgp-limit-choices-spots-left.php hosted with ❤ by GitHub
Do not disable exhausted choices
If you don’t want to disable exhausted choices for any particular reason (like using them for conditional logic), then just add this code to your theme’s functions.php file:GRAVITY PERKS LIMIT CHOICES
add_filter( 'gplc_disable_choices', '__return_false' );
FAQs
Can I Set the Limit Daily?
Of course, you can! Check out this snippet to allow you to make that limit apply only to the current day.
Hooks
- gplc_choice_counts
- gplc_completed_payments_only
- gplc_not_enough_stock_message
- gplc_out_of_stock_message