How to add third-party PayPal plugin support for affiliate payouts

Affiliate for WooCommerce plugin helps you to add, manage affiliates, and track performance from a single place – commissions, sales, payouts, leaderboard, etc. Earn money without hard work. Increase your brand outreach, and get potential customers.

Scope of support:

This documentation is intended for developers. We are happy to offer guidance, but support for store-specific customizations is not covered under our Support Policy.

Please proceed only if you are comfortable with PHP, custom development, and troubleshooting. If not, we recommend working with a developer.

The plugin offers multiple payout options, including: PayPal, Stripe, Coupons (Fixed cart discount), Store Credit Coupons, and Manual Payout.

For Payout via PayPal, Affiliate for WooCommerce natively supports PayPal payouts using the WooCommerce PayPal Payments plugin (learn more).

However, the payout system is extensible and allows developers to integrate other PayPal plugins.

How to integrate with other PayPal plugins for commission payout?

↑ Back to top

If your store uses a different PayPal plugin (other than WooCommerce PayPal Payments), you can still integrate it for commission payout.

To achieve this, you must override two filters:

  • The Payout Method: To tell Affiliate for WooCommerce to use the PayPal REST API handler.
  • The Credentials: To inject the Client ID and Secret from your existing plugin.

Note:

This doc demonstrates integration with the Payment Plugins for PayPal WooCommerce plugin as an example.

Plugin folder and file name: pymntpl-paypal-woocommerce/pymntpl-paypal-woocommerce.php

Override the PayPal Payout method

↑ Back to top

The Affiliate for WooCommerce plugin determines the PayPal payout method internally. You can override this behavior using the following filter: afwc_payout_paypal_payment_method

add_filter( 'afwc_payout_paypal_payment_method', 'afwc_use_paypal_payments_method', 10, 2 );

function afwc_use_paypal_payments_method( $method = '', $info = array() ) {
	if ( ! is_array( $info ) || empty( $info['source'] ) || ! is_object( $info['source'] ) ) {
		return $method;
	}

	$source = $info['source'];
	if ( 'paypal_masspay' === $source->payout_method ) {
		return $method;
	}

	if ( function_exists( 'afwc_is_plugin_active' ) && afwc_is_plugin_active( 'pymntpl-paypal-woocommerce/pymntpl-paypal-woocommerce.php' ) ) {
		return 'paypal_payments';
	}

	return $method;
}

What does this do?

  • Checks whether the payout source is available.
  • Verifies that the Payment Plugins for PayPal WooCommerce plugin is active.
  • Switches the payout method to paypal_payments .

Provide PayPal API credentials from the plugin

↑ Back to top

Affiliate for WooCommerce plugin requests PayPal credentials using the following filter: afwc_set_paypal_payments_credentials

add_filter( 'afwc_payout_paypal_payment_credentials', 'afwc_set_paypal_payments_credentials', 10, 2 );

function afwc_set_paypal_payments_credentials( $credentials = array(), $info = array() ) {
	if ( ! is_array( $info ) || empty( $info['source'] ) || ! is_object( $info['source'] ) ) {
		return $credentials;
	}

	if ( ! function_exists( 'afwc_is_plugin_active' ) || ! afwc_is_plugin_active( 'pymntpl-paypal-woocommerce/pymntpl-paypal-woocommerce.php' ) ) {
		return $credentials;
	}

	$settings = get_option( 'woocommerce_ppcp_api_settings', array() );
	if ( empty( $settings ) || ! is_array( $settings ) ) {
		return $credentials;
	}

	$environment = ! empty( $settings['environment'] ) ? $settings['environment'] : 'production';
	$is_sandbox  = ( 'sandbox' === $environment );

	$client_id_key = $is_sandbox ? 'client_id_sandbox' : 'client_id_production';
	$secret_key    = $is_sandbox ? 'secret_key_sandbox' : 'secret_key_production';

	return array(
		'testmode' => $is_sandbox,
		'username' => ! empty( $settings[ $client_id_key ] ) ? $settings[ $client_id_key ] : '',
		'password' => ! empty( $settings[ $secret_key ] ) ? $settings[ $secret_key ] : '',
	);
}

How are credentials mapped?

Affiliate for WooCommerce uses generic keys (username, password) to handle different API types. For PayPal Payouts, map your credentials as follows:

Affiliate for WooCommerce FieldPayPal Plugin Setting
testmodeEnvironment = Sandbox
usernamePayPal Client ID
passwordPayPal Secret Key

Affiliate for WooCommerce uses these values internally to authenticate PayPal payout requests.

Does it support Sandbox and Production environments?

↑ Back to top

This integration automatically supports both environments:

  • Sandbox credentials are used when the PayPal plugin is in sandbox mode.
  • Production credentials are used when live mode is enabled.

No additional configuration is required.

Best practices

↑ Back to top
  • Validate PayPal credentials in the PayPal plugin before running payouts.
  • Always test payouts using sandbox mode before enabling production.

Tips to use custom code on your site

↑ Back to top

You can securely add code snippets to your site using either of the methods mentioned here: How to properly add WooCommerce custom code.

We recommend backing up your site before adding custom code and testing it thoroughly in a staging environment.

Feature request

↑ Back to top

Have a feature request or enhancement suggestion for Affiliate For WooCommerce? Submit a request or send it to us from here.

Related Products

Let customers subscribe to your products or services and pay on a weekly, monthly or annual basis.

Power your membership association, online magazine, elearning sites, and more with access control to content/products and member discounts.