bookmark_bordergform_product_info

Description

This filter is fired every time Gravity Forms request 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

    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 );

Source Code

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