|
/ Documentation /Developer Hooks & Events/ suredonation_paypal_sdk_args Filter Hook

suredonation_paypal_sdk_args Filter Hook

Overview

The suredonation_paypal_sdk_args filter allows developers to modify the query arguments used when SureDonation loads the PayPal JavaScript SDK for a donation form.

You can use this filter to customize how the PayPal SDK is loaded, such as setting a specific locale or adding supported PayPal SDK parameters.

SureDonation Pro also uses this filter to modify the SDK configuration for subscription forms, including parameters such as vault=true and intent=subscription.

When to Use This Filter

Use this filter when you need to customize the PayPal JavaScript SDK configuration.

For example, you can use it to:

  • Set a specific PayPal locale.
  • Modify the payment intent.
  • Add supported PayPal SDK parameters.
  • Customize the SDK configuration for specific forms.
  • Support custom PayPal integration requirements.

Filter Signature

apply_filters( 'suredonation_paypal_sdk_args', $sdk_args, $form_id);

Parameters

ParameterTypeDescription
$sdk_argsarrayQuery arguments used to load the PayPal JavaScript SDK.
$form_idintThe SureDonation donation form post ID for which the SDK is being loaded.

Default SDK Arguments

The $sdk_args array contains the following default parameters:

ParameterDefault ValueDescription
client-idPartner client IDIdentifies the PayPal partner application.
merchant-idConnected seller merchant IDIdentifies the connected PayPal seller account.
currencySite currencyCurrency configured for the site.
componentsbuttonsLoads the PayPal Buttons component.
intentcaptureDefines the default PayPal payment intent.

Return Value

Return the modified $sdk_args array.

The returned values are converted into the query string used when loading:

https://www.paypal.com/sdk/js

Basic Usage

Use add_filter() to register your callback.

add_filter('suredonation_paypal_sdk_args', 'your_custom_function',10,  2);

function your_custom_function( $sdk_args, $form_id ) {

    // Modify the SDK args here.

    return $sdk_args;

}

Example: Set the PayPal Locale

The following example sets the buyer-facing PayPal locale to en_US.

add_filter( 'suredonation_paypal_sdk_args', 'mysite_paypal_locale', 10, 2);

function mysite_paypal_locale( $sdk_args, $form_id ) {

    // Force a specific buyer-facing locale.

    $sdk_args['locale'] = 'en_US';

    return $sdk_args;

}

Example: Apply a Setting to a Specific Form

You can use the $form_id parameter to customize the PayPal SDK configuration for a specific donation form.

add_filter( 'suredonation_paypal_sdk_args',  'mysite_custom_paypal_settings',   10, 2);

function mysite_custom_paypal_settings( $sdk_args, $form_id ) {

    if ( 123 === $form_id ) {

        $sdk_args['locale'] = 'en_US';

    }

    return $sdk_args;

}

Replace 123 with the ID of the donation form where you want to apply the custom configuration.

Example: Add a Supported SDK Parameter

You can add additional supported PayPal SDK parameters when required.

add_filter( 'suredonation_paypal_sdk_args', 'mysite_add_paypal_parameter',  10,  2);

function mysite_add_paypal_parameter( $sdk_args, $form_id ) {

    $sdk_args['buyer-country'] = 'US';

    return $sdk_args;

}

Only add parameters supported by the PayPal JavaScript SDK.

PayPal Subscription Support

SureDonation Pro uses this filter to customize the PayPal SDK configuration for subscription forms.

For subscription payments, additional parameters can include:

  • vault=true
  • intent=subscription

These parameters allow the PayPal SDK to support subscription-related functionality.

SDK Loading Flow

The filter is part of the PayPal SDK loading process:

  1. SureDonation loads a donation form.
  2. SureDonation checks whether the form uses PayPal.
  3. SureDonation verifies that the PayPal partner client ID and merchant ID are available.
  4. The default PayPal SDK arguments are prepared.
  5. The suredonation_paypal_sdk_args filter is applied.
  6. Your callback can modify the SDK arguments.
  7. SureDonation builds the PayPal SDK URL using the returned arguments.
  8. The PayPal JavaScript SDK is loaded for the donation form.

This filter is applied inside:

PayPal_Settings::maybe_enqueue_paypal_sdk()

The filter only runs after SureDonation confirms that:

  • The donation form uses PayPal.
  • The PayPal partner client ID is available.
  • The connected merchant ID is available.

When modifying $sdk_args, always return the complete array so the required PayPal SDK parameters are preserved.

Related Hooks

  • suredonation_paypal_webhook_handle_event: Allows developers to handle additional PayPal webhook events.
  • suredonation_enqueue_form_frontend_scripts: Allows developers to enqueue additional frontend scripts for SureDonation forms.
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top