Using Gravity Forms ‘gform_product_info_name_include_field_label’ PHP filter

The gform_product_info_name_include_field_label filter allows you to control whether the field label is included in the product name for radio and select type Product fields in Gravity Forms.

Usage

add_filter('gform_product_info_name_include_field_label', '__return_true');

Parameters

This filter has no parameters.

More information

See Gravity Forms Docs: gform_product_info_name_include_field_label

Place this code in your active theme’s functions.php file.

Examples

Include field label in product name

To include the field label in the product name for radio and select type Product fields:

add_filter('gform_product_info_name_include_field_label', 'include_field_label_in_product_name');
function include_field_label_in_product_name() {
    // Include the field label in the product name
    return true;
}

Exclude field label from product name

To exclude the field label from the product name for radio and select type Product fields:

add_filter('gform_product_info_name_include_field_label', 'exclude_field_label_from_product_name');
function exclude_field_label_from_product_name() {
    // Exclude the field label from the product name
    return false;
}

Include field label only for specific form

To include the field label in the product name for radio and select type Product fields only for a specific form:

add_filter('gform_product_info_name_include_field_label', 'include_field_label_in_product_name_for_specific_form', 10, 2);
function include_field_label_in_product_name_for_specific_form($include_label, $form) {
    // Include the field label only for form ID 5
    if ($form['id'] == 5) {
        return true;
    }
    return $include_label;
}

Include field label only for specific product field

To include the field label in the product name only for a specific product field:

add_filter('gform_product_info_name_include_field_label', 'include_field_label_in_product_name_for_specific_field', 10, 3);
function include_field_label_in_product_name_for_specific_field($include_label, $form, $field) {
    // Include the field label only for field ID 8
    if ($field['id'] == 8) {
        return true;
    }
    return $include_label;
}

Include field label based on user role

To include the field label in the product name for radio and select type Product fields based on the user role:

add_filter('gform_product_info_name_include_field_label', 'include_field_label_in_product_name_based_on_user_role');
function include_field_label_in_product_name_based_on_user_role() {
    // Get the current user
    $current_user = wp_get_current_user();

    // Include the field label if the current user is an administrator
    if (in_array('administrator', $current_user->roles)) {
        return true;
    }
    return false;
}