gplc_choice_limit

  1. Description
  2. Usage
  3. Parameters
  4. Since
  5. Examples
    1. Override limit of a specific choice

Description

Filter the choice limit for a given choice.

Usage

Apply to all fields on all forms.

add_filter( 'gplc_choice_limit', 'my_custom_function' );

Apply to all fields on a specific form.

add_filter( 'gplc_choice_limit_FORMID', 'my_custom_function' );

Apply to a specific field on a specific form.

add_filter( 'gplc_choice_limit_FORMID_FIELDID', 'my_custom_function' );

Parameters

  • limit int

    The current choice’s limit.

  • choice array

    The current choice array.

  • form_id int

    The current form ID to which the choice belongs.

  • field_id int

    The current field ID to which the choice belongs.

Since

This filter is available since Gravity Forms Limit Choices 1.1.2.

Examples

Override limit of a specific choice

Let’s imagine that you have a field (ID: 1) on a form (ID: 123) and you have a default limit of 10 setup for each choice. You want to override a specific choice, identified by its value (e.g. First Choice ) and set its limit to 1.

<?php
/**
 * Gravity Perks // Limit Choices // Override Limit of Specific Choice
 * https://gravitywiz.com/documentation/gravity-forms-limit-choices/
 */
// Update "123" to the form ID and "4" to the field ID.
add_filter( 'gplc_choice_limit_123_4', function( $limit, $choice ) {
	if ( $choice['value'] === 'First Choice' ) {
		// Update "1" to the desired limit.
		$limit = 1;
	}
	return $limit;
}, 10, 2 );