Using Gravity Forms ‘gform_product_qty’ PHP filter

The gform_product_qty filter is executed when displaying the order information grid on the entry detail page and notification emails. This filter is used to modify the “Qty” heading.

Usage

add_filter('gform_product_qty', 'your_function_name', 10, 2);

Parameters

  • $label (string): The label to be filtered.
  • $form_id (integer): The current form’s ID.

More information

See Gravity Forms Docs: gform_product_qty

Examples

Change the default Qty label

This example changes the default “Qty” label to “Quantity”:

add_filter('gform_product_qty', 'change_qty', 10, 2);

function change_qty($label, $form_id) {
    return 'Quantity';
}

Add form ID to the Qty label

This example appends the form ID to the “Qty” label:

add_filter('gform_product_qty', 'add_form_id_to_qty', 10, 2);

function add_form_id_to_qty($label, $form_id) {
    return $label . ' (Form ' . $form_id . ')';
}

Change the Qty label for a specific form

This example changes the “Qty” label only for a form with a specific ID:

add_filter('gform_product_qty', 'change_qty_for_specific_form', 10, 2);

function change_qty_for_specific_form($label, $form_id) {
    if ($form_id == 5) {
        return 'Custom Quantity';
    }
    return $label;
}

Change the Qty label based on user role

This example changes the “Qty” label based on the user’s role:

add_filter('gform_product_qty', 'change_qty_based_on_user_role', 10, 2);

function change_qty_based_on_user_role($label, $form_id) {
    $user = wp_get_current_user();

    if (in_array('administrator', (array) $user->roles)) {
        return 'Admin Quantity';
    }
    return $label;
}

Use a custom translation for the Qty label

This example uses a custom translation function for the “Qty” label:

add_filter('gform_product_qty', 'translate_qty_label', 10, 2);

function translate_qty_label($label, $form_id) {
    return my_custom_translation_function($label);
}