gform_submission_data_pre_process_payment

Description

This filter can be used to modify the Submission Data before it’s used during feed processing by a payment add-on based on the Add-On Framework.

Usage

The base filter which would run for all forms with a payment add-on feed would be used like so:

add_filter( 'gform_submission_data_pre_process_payment', 'your_function_name', 10, 4 );

To target a specific form append the form id to the hook name. (format: gform_submission_data_pre_process_payment_FORMID)

add_filter( 'gform_submission_data_pre_process_payment_10', 'your_function_name', 10, 4 );

Parameters

  • $submission_data Submission Data Object

    Contains the form title, payment amount, setup fee amount, trial amount, line items created using the submitted pricing field values, and any discounts from coupons.

  • $feed Feed Object

    The feed currently being processed.

  • $form Form Object

    The form currently being processed.

  • $entry Entry Object

    The entry currently being processed.

Examples

1. Change the Payment Amount

This example shows how you can override the payment_amount for form 10 with the value from field 5.

add_filter( 'gform_submission_data_pre_process_payment_10', 'modify_submission_data', 10, 4 );
function modify_submission_data( $submission_data, $feed, $form, $entry ) {
    $submission_data['payment_amount'] = rgar( $entry, '5' );

    return $submission_data;
}

2. Set the Number of Trial Days

This example shows how you can override the trial property (i.e. the number of trial days) for form 5.

add_filter( 'gform_submission_data_pre_process_payment_5', 'modify_submission_data', 10, 4 );
function modify_submission_data( $submission_data, $feed, $form, $entry ) {

if (  $feed['meta']['feedName'] != 'feed name goes here' ) { // Update this line to your feed name
        return;
    }

    $submission_data['trial'] = 15;

    return $submission_data;
}

3. Set the Authorize.Net Line Item Taxable Status

This example shows how you can override the default taxable status of Y to N for the line items of form 3. This is supported as of Authorize.Net version 2.2.1.

add_filter( 'gform_submission_data_pre_process_payment_3', 'override_line_item_tabaxable', 10, 4 );
function override_line_item_tabaxable( $submission_data, $feed, $form, $entry ) {
	foreach ( $submission_data['line_items'] as &$line_item ) {
		$line_item['taxable'] = 'N';
	}

	return $submission_data;
}

4. Customize the name for a Line Item

This example shows how you can override the name of a line item, from the default (product label “My Product”) to a custom name.

add_filter( 'gform_submission_data_pre_process_payment', 'gf_custom_lite_item_name', 10, 4 );
function gf_custom_lite_item_name( $submission_data, $feed, $form, $entry ) {
    foreach ( $submission_data['line_items'] as &$line_item ) {
		GFCommon::log_debug( __METHOD__ . '(): Line Item Name => ' . $line_item['name'] );
        if ( $line_item['name'] == 'My Product' ){
			$line_item['name'] = 'Custom Name Text Here';
		}
    }
 	GFCommon::log_debug( __METHOD__ . '(): Modified Submission Data => ' . print_r( $submission_data, true ) );
    return $submission_data;
}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

gf_apply_filters( 'gform_submission_data_pre_process_payment', $form['id'], $submission_data, $feed, $form, $entry );

This filter is located in GFPaymentAddOn::get_submission_data() in includes/addon/class-gf-payment-addon.php.

Since

This filter was added in Gravity Forms 1.9.12.8.