Using Gravity Forms ‘gform_paypalpaymentspro_args_before_send’ PHP filter

The gform_paypalpaymentspro_args_before_send filter allows you to modify the transaction arguments before they are sent to PayPal.

Usage

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

Parameters

  • $nvp (array): The transaction arguments.
  • $form_id (int): The ID of the current form.

More information

See Gravity Forms Docs: gform_paypalpaymentspro_args_before_send

Examples

Change the last name

This example modifies the last name in the transaction arguments before sending to PayPal.

add_filter('gform_paypalpaymentspro_args_before_send', 'change_args', 10, 2);
function change_args($nvp, $form_id) {
    $nvp['LASTNAME'] = 'Testing';
    return $nvp;
}

Add a custom description

This example adds a custom description to the transaction arguments.

add_filter('gform_paypalpaymentspro_args_before_send', 'add_custom_description', 10, 2);
function add_custom_description($nvp, $form_id) {
    $nvp['DESC'] = 'Custom Transaction Description';
    return $nvp;
}

Change the currency

This example changes the currency of the transaction to Euros (EUR).

add_filter('gform_paypalpaymentspro_args_before_send', 'change_currency', 10, 2);
function change_currency($nvp, $form_id) {
    $nvp['CURRENCY'] = 'EUR';
    return $nvp;
}

Add a discount

This example adds a discount to the transaction amount.

add_filter('gform_paypalpaymentspro_args_before_send', 'add_discount', 10, 2);
function add_discount($nvp, $form_id) {
    $nvp['AMT'] = $nvp['AMT'] - 5; // Apply a $5 discount
    return $nvp;
}

Change the email address

This example changes the email address in the transaction arguments.

add_filter('gform_paypalpaymentspro_args_before_send', 'change_email', 10, 2);
function change_email($nvp, $form_id) {
    $nvp['EMAIL'] = '[email protected]';
    return $nvp;
}

Remember to add the code to the functions.php file of your active theme.