gform_product

gform_product

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is executed when displaying the order information grid on the entry detail page and notification emails. Use this filter to modify the 「Product」 heading.
Usage
1add_filter( 'gform_product', 'change_product', 10, 2 );

Parameters

$label string
The label to be filtered.

$form_id integer
The current form』s id.

Examples
This example changes the default Product label:
1234add_filter( 'gform_product', 'change_product', 10, 2 );function change_product( $label, $form_id ) {    return 'Services';}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:

GFCommon::get_submitted_pricing_fields() in common.php
GFEntryDetail::lead_detail_grid() in entry_detail.php

gform_product_unitprice

gform_product_unitprice

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is executed when displaying the order information grid on the entry detail page and notification emails. Use this filter to modify the 「Unit Price」 heading.
Usage
1add_filter( 'gform_product_unitprice', 'change_unitprice', 10, 2 );
Parameters

$label string
The label to be filtered.

$form_id integer
The current form』s id.

Examples
This example changes the default Unit Price label:
1234add_filter( 'gform_product_unitprice', 'change_unitprice', 10, 2 );function change_unitprice( $label, $form_id ) {    return 'Sub Total';}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:

GFCommon::get_submitted_pricing_fields() in common.php
GFEntryDetail::lead_detail_grid() in entry_detail.php

gform_product_total

gform_product_total

DescriptionUsageParametersExamples1. Add a value to the total2. Prevent totals less than zeroSource Code

Description
Fires right before updating the Total value for forms with pricing fields. Allows users to implement custom logic to manipulate the Total value.
NOTE: This filter only applies to the form front end javascript, and will only change the display of the Total. You must also implement the gform_product_info to make sure the total is displayed properly in the entry pages and sent properly to third party services via Add-Ons such as the PayPal Add-On
The best location to put this javascript code is by adding an HTML field to your form and place the javascript code in that field, wrapped with the script tags.
An alternative placement is to put the javascript in the gform_pre_render hook.
Usage
gform.addFilter( 'gform_product_total', function(total, formId){
// do something with the total
return total;
} );

Parameters

total float
The total to be filtered.

formId integer
The ID of the form in use.

Examples
1. Add a value to the total
This example adds $50 to the total price if the quantity field is greater than 100

2. Prevent totals less than zero

Source Code
This filter is located in gravityforms.js

gform_product_quantity

gform_product_quantity

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to change the sub-label for the Product Quantity input.
Usage
1add_filter( 'gform_product_quantity', 'set_quantity_label', 10, 2 );
You can also target a specific form by adding the form id after the hook name.
1add_filter( 'gform_product_quantity_6', 'set_quantity_label', 10, 2 );
Parameters

$sublabel string
The sub-label to be filtered.

$form_id integer
ID of current form.

Examples
This example changes the quantity sub-label to 「How many:」.
1234add_filter( 'gform_product_quantity_185', 'set_quantity_label', 10, 2 );function set_quantity_label( $sublabel, $form_id ) {    return 'How many:';}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:

GF_Field_Calculation::get_field_input() in includes/fields/class-gf-field-calculation.php
GF_Field_SingleProduct::get_field_input() in includes/fields/class-gf-field-singleproduct.php

gform_product_qty

gform_product_qty

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is executed when displaying the order information grid on the entry detail page and notification emails. Use this filter to modify the 「Qty」 heading.
Usage
1add_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.

Examples
This example changes the default Qty label:
1234add_filter( 'gform_product_qty', 'change_qty', 10, 2 );function change_qty( $label, $form_id ) {    return 'Quantity';}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:

GFCommon::get_submitted_pricing_fields() in common.php
GFEntryDetail::lead_detail_grid() in entry_detail.php

gform_product_price

gform_product_price

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to change the sub-label for the Product Price input.
Usage
The following would apply to all forms:
add_filter( 'gform_product_price', 'your_function_name', 10, 2 );

You can also target a specific form by adding the form id after the hook name. (format: gform_product_price_FORMID)
add_filter( 'gform_product_price_6', 'your_function_name', 10, 2 );

Parameters

$sublabel string
The sub-label to be filtered.

$form_id integer
ID of current form.

Examples
This example changes the price sub-label to 「Cost:」.
add_filter( 'gform_product_price_185', 'set_price_label', 10, 2 );
function set_price_label( $sublabel, $form_id ) {
return 'Cost';
}

Please note: The colon will be added automatically after the label.
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in the following methods:

GFCommon::get_submitted_pricing_fields() in common.php
GFEntryDetail::lead_detail_grid() in entry_detail.php
GF_Field_Calculation::get_field_input() in includes/fields/class-gf-field-calculation.php
GF_Field_SingleProduct::get_field_input() in includes/fields/class-gf-field-singleproduct.php

gform_product_info

gform_product_info

DescriptionUsageParametersExamples1. Add an extra line item2. Replace all the line items3. Modify product name4. Use the choice text on the Entry Detail pageSource Code

Description
This filter is fired every time Gravity Forms requests the list of products saved in an entry.
Use this filter to manipulate the list of products displayed in the entry detail and sent to third party services via Add-Ons such as the PayPal Add-On.
Note that this filter only applies to the creation of new entries, and will not fire when loading existing cached entries. To manipulate existing entries, you may need to delete the cached entry data first.
Usage
The following would apply to all forms using pricing fields.
add_filter( 'gform_product_info', 'your_function_name', 10, 3 );

To limit the scope of the function to a specific form simply append the form id after the hook name. (format: gform_product_info_FORMID)
add_filter( 'gform_product_info_6', 'your_function_name', 10, 3 );

Parameters

$product_info array
The array containing the product information. This array is in the following format:
Array
(
[products] => Array
(
[1] => Array
(
[name] => Some Product
[price] => $1,000.00
[quantity] => 2
[options] => Array
(
[0] => Array
(
[field_label] => Option
[option_name] => First Option
[option_label] => Option: First Option
[price] => 1
)

)

)

)

[shipping] => Array
(
[name] => Shipping
[price] => 5
)

)

$form Form Object
The form currently being processed.

$entry Entry Object
The entry currently being processed.

Examples
1. Add an extra line item
This example adds an Extra Fee line item if the quantity is greater than 200.
add_filter( 'gform_product_info', 'add_fee', 10, 3 );
function add_fee( $product_info, $form, $lead ) {

$quantity = $product_info['products'][1]['quantity'];
if ( $quantity > 200 ) {
$product_info['products']['extra_fee'] = array( 'name' => 'Extra Fee', 'price' => 50, 'quantity' => 1 );
}

return $product_info;
}

2. Replace all the line items
This example shows how you can replace all the line items with a custom line item.
add_filter( 'gform_product_info', function( $product_info, $form, $entry ) {
if ( rgar( $entry, 19 ) == 'Pay250DepositOnly' ) {
$product_info = array(
'products' => array(
array(
'name' => 'Deposit',
'price' => 250,
'quantity' => 1,
),
),
);
}

return $product_info;
}, 10, 3 );

3. Modify product name
This example shows how you can append the field description to the product names.
add_filter( 'gform_product_info', function ( $product_info, $form, $entry ) {
foreach ( $product_info['products'] as $key => &$product ) {
$field = GFFormsModel::get_field( $form, $key );
if ( is_object( $field ) ) {
$product['name'] .= ' - ' . $field->description;
}
}

return $product_info;
}, 10, 3 );

4. Use the choice text on the Entry Detail page
When preparing the order summary data for display on the Entry Detail page Gravity Forms uses the choice values, this example regenerates the data using the choice text instead.
add_filter( 'gform_product_info', 'entry_detail_product_info_use_choice_text', 10, 3 );
function entry_detail_product_info_use_choice_text( $product_info, $form, $entry ) {
if ( GFCommon::is_entry_detail() ) {
remove_filter( 'gform_product_info', 'entry_detail_product_info_use_choice_text' );
$product_info = GFCommon::get_product_fields( $form, $entry, true, true );
add_filter( 'gform_product_info', 'entry_detail_product_info_use_choice_text', 10, 3 );
}

return $product_info;
}

Source Code
This filter is located in GFCommon::get_product_fields() in common.php.

gform_product_info_name_include_field_label

gform_product_info_name_include_field_label

DescriptionUsageParametersPlacementSource Code

Description
This filter is used to control the inclusion of the field label in the product name for radio and select type Product fields. It only applies to the product information which is generated during submission, which is used by notifications, confirmations, add-ons and the entry detail page in the admin.
Usage
Include the field label.
1add_filter( 'gform_product_info_name_include_field_label', '__return_true' );
Parameters
This hook has no parameters.
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::get_product_fields() in common.php.

gform_product_field_types

gform_product_field_types

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Filters the input types to use when checking if a field is a product field, allowing support for custom product fields.
Usage
add_filter( 'gform_product_field_types', 'your_function_name' );

Parameters

$product_fields array
An array of the product field types.
The default product types are:
array(
'option',
'quantity',
'product',
'total',
'shipping',
'calculation',
'price',
'hiddenproduct',
'singleproduct',
'singleshipping'
)

Examples
add_filter( 'gform_product_field_types', 'set_product_types' );
function set_product_types( $product_types ){
if ( ! in_array('my_custom_product', $product_types)){
$product_types[] = 'my_custom_product';
}

return $product_types;
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms 1.9.14.
Source Code
This filter is located in GFCommon::is_product_field() in common.php.

gform_process_template_shortcodes_pre_create_post

gform_process_template_shortcodes_pre_create_post

DescriptionUsageParametersExamples1. Enable for all forms2. Disable for a specific formPlacementSource CodeSince

Description
This filter can be used to prevent shortcodes used in the post custom field or post title field templates from being processed.
Usage
Applies to all forms:
1add_filter( 'gform_process_template_shortcodes_pre_create_post', 'your_function_name', 10, 3 );
Applies to a specific form:
1add_filter( 'gform_process_template_shortcodes_pre_create_post_5', 'your_function_name', 10, 3 );
Parameters

$process_template_shortcodes boolean
Is shortcode processing enabled? Default is false for the post content or true in other areas.

$field_type string
The field type currently being processed. Possible values: post_custom_field, post_content, or post_title.

$post_data array
The post data prepared from the current entry.

$form Form Object
The current form object.

$feed Feed Object
The current feed object.

Examples
1. Enable for all forms
This example shows how you can enable shortcode processing for all forms.
1add_filter( 'gform_process_template_shortcodes_pre_create_post', '__return_true' );
2. Disable for a specific form
1add_filter( 'gform_process_template_shortcodes_pre_create_post_5', '__return_false' );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
1$process_template_shortcodes = apply_filters( 'gform_process_template_shortcodes_pre_create_post', $process_template_shortcodes, $field_type, $post_data, $form, $entry );
This filter is located in GFFormsModel::process_post_template() in forms_model.php.
Since
This filter was added in Gravity Forms 2.0.0.4.