Description
Use this filter to modify the query string that will be sent to PayPal. This filter is fired immediately before the user is redirected to PayPal.
Usage
add_filter( 'gform_paypal_query', 'your_function_name', 10, 5 );
Parameters
- $query_string string
The query string that will be sent to PayPal; includes the invoice ID, currency, customer fields, products, quantities, prices, and various other PayPal settings.
-
$form Form Object
The Form Object of the entry from which this query string is generated.
-
$entry Entry Object
The Entry Object from which this query string is generated.
-
$feed Feed Object
The feed which is 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. Added in PayPal 2.4.4.
Examples
Modify Pricing
This example demonstrates how to remove negative prices from the query string (which are would otherwise generate an error with PayPal) and to subtract that value from the highest priced item.
add_filter( 'gform_paypal_query', 'update_paypal_query', 10, 3 ); function update_paypal_query( $query_string, $form, $entry ) { parse_str( $query_string, $query ); $id = 0; $amounts = array(); foreach ( $query as $key => $value ) { if ( (int) $value >= 0 ) { $amounts[] = $value; continue; } else { $id = str_replace( 'amount_', '*', $key ); $discount = abs( $value ); } } if ( $id ) { unset( $query['item_name_' . $id] ); unset( $query['amount_' . $id] ); unset( $query['quantity_' . $id] ); } foreach ( $query as $key => &$value ) { if ( strpos( $key, 'amount_' ) !== false ) { $value = $value - $discount; } } $query_string = http_build_query( $query, '', '&' ); return '&' . $query_string; }
Disable Tax
This example shows how you can disable tax:
add_filter( 'gform_paypal_query', 'update_paypal_query', 10, 3 ); function update_paypal_query( $query_string, $form, $entry ) { $my_forms = array( 1, 5, 7, 9, 276 ); // list of form id's to apply this separated by comma // skip processing if the form id is not in the array of forms id's if ( !in_array( $form['id'], $my_forms ) ) { return $query_string; } // apply only if form ID is 1 parse_str( $query_string, $query ); $query['tax_1'] = '0.00'; $query['tax_2'] = '0.00'; $query['tax_3'] = '0.00'; $query['tax_4'] = '0.00'; $query['tax_5'] = '0.00'; $query['tax'] = '0.00'; $query_string = http_build_query( $query, '', '&' ); return '&' . $query_string; }
Set the Language Code
This example shows how you can set the language code. You can find the full list of language codes in PayPal’s developer documentation.
add_filter( 'gform_paypal_query', 'update_paypal_query', 10, 3 ); function update_paypal_query( $query_string, $form, $entry ) { if ( $form['id'] == 323 ) { $query_string .= '&lc=en_GB'; } else { $query_string .= '&lc=en_US'; } return $query_string; }
And your Logo to Checkout page
This example shows how you can set the image URL to display your logo in PayPal’s checkout page.
add_filter( 'gform_paypal_query', 'add_image_url', 10, 3 ); function add_image_url( $query_string, $form, $entry ) { // Update 1 to your form id. Remove the if statement if you want to add the image to all forms. if ( $form['id'] == 1 ) { $query_string .= '&image_url=https://example.com/some/path/image.png'; // Size of the image must be 150 x 150 pixels } return $query_string; }
Add Invoice number
This example shows how you can populate the invoice parameter with a value from a field in your form.
add_filter( 'gform_paypal_query', 'add_invoice_number', 10, 3 ); function add_invoice_number( $query_string, $form, $entry ) { // Update 1 with the id number for the field that contains your invoice number $invoice_number = rgar( $entry, '1' ); // Update 323 with your form id if ( $form['id'] == 323 ) { $query_string .= '&invoice=' . $invoice_number; } return $query_string; }
Set the landing page
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
gf_apply_filters( 'gform_paypal_query', $form['id'], $query_string, $form, $entry, $feed, $submission_data )
This filter is located in GFPayPal::redirect_url() in class-gf-paypal.php.