Using Gravity Forms ‘gform_paypalpaymentspro_args_before_payment’ PHP filter

The gform_paypalpaymentspro_args_before_payment Gravity Forms PHP filter allows you to modify the product transaction arguments before they are sent to PayPal.

Usage

add_filter('gform_paypalpaymentspro_args_before_payment', 'your_function_name', 10, 5);

Parameters

  • $args (array) – An associative array containing the billing details, payment amount, and line items created using the submitted pricing field values and any discounts from coupons.
  • $form_id (integer) – The ID of the form currently being processed.
  • $submission_data (Submission Data) – 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. Available from v2.0.
  • $feed (Feed Object) – The Feed which is currently being processed. Available from v2.0.
  • $entry (Entry Object) – The Entry which is currently being processed. Available from v2.0.

More information

See Gravity Forms Docs: gform_paypalpaymentspro_args_before_payment

Examples

Add New Parameter

This example sets the COMMENT1 parameter using the value from a form field. Check the PayPal API documentation for supported parameters.

add_filter('gform_paypalpaymentspro_args_before_payment', function($args, $form_id) {
    // Change 3 to the id number of your form.
    if ($form_id == 3) {
        // Change 5 to the id number of the field containing the information.
        $args['COMMENT1'] = rgpost('input_5');
    }
    return $args;
}, 10, 2);

Map Billing Address to Shipping Address

This example maps the billing address to the shipping address.

add_filter('gform_paypalpaymentspro_args_before_payment', 'gf_add_shipping_address', 10, 2);

function gf_add_shipping_address($args, $form_id) {
    gf_paypalpaymentspro()->log_debug(__METHOD__ . '(): Running...');

    $args["SHIPTOLASTNAME"] = $args["LASTNAME"];
    $args["SHIPTOSTREET"] = $args["STREET"];
    $args["SHIPTOCITY"] = $args["CITY"];
    $args["SHIPTOSTATE"] = $args["STATE"];
    $args["SHIPTOZIP"] = $args["ZIP"];
    $args["SHIPTOCOUNTRY"] = $args["BILLTOCOUNTRY"];

    gf_paypalpaymentspro()->log_debug(__METHOD__ . '(): Modified $args: ' . print_r($args, true));

    return $args;
}

Placement: Your code snippet should be placed in the functions.php file of your active theme.

Source Code: This filter is located in GFPayPalPaymentsPro::authorize() in class-gf-paypalpaymentspro.php.