The WooCommerce plugin comes with its own free version of PayPal Standard. PayPal can be enabled via the WooCommerce settings and once your PayPal email is entered your WooCommerce shop is ready to take PayPal payments.
Now, there is extensive documentation online which explains, with a little bit of code, how to switch PayPal account programmatically and conditionally i.e. for a given product ID or product category slug. For example, you may want to use a PayPal account for consulting services, another for online courses and another for physical products.
By adding this simple code and hooking into woocommerce_paypal_args is indeed possible to use different / multiple PayPal Standard accounts in a single WooCommerce installation.
However, there is an outstanding problem with “IPN Validation“: once you tell WooCommerce to use a different PayPal email account, the WooCommerce order is correctly placed, but its status goes “on hold” because IPN validation on the PayPal end fails (and that’s because you’re using a different PayPal account).
So, here’s the fully working version, included the IPN validation fix. Please read the disclaimer below and – only then – enjoy!

PHP Snippet: Use Different PayPal Standard Account For a Product ID @ WooCommerce Checkout
/**
* @snippet Switch PayPal Account @ WooCommerce Checkout
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer, BusinessBloomer.com
* @testedwith WooCommerce 4.6
* @community https://businessbloomer.com/club/
*/
// -------------------
// 1. Switch PayPal email for Product ID
add_filter( 'woocommerce_paypal_args' , 'bbloomer_switch_paypal_email_based_product', 9999, 2 );
function bbloomer_switch_paypal_email_based_product( $paypal_args, $order ) {
foreach ( $order->get_items() as $item_id => $item ) {
// ENTER PRODUCT ID HERE
if ( 123456 == $item->get_product_id() ) {
// ENTER OTHER PAYPAL EMAIL HERE
$paypal_args['business'] = 'another-paypal@example.com';
break;
}
}
return $paypal_args;
}
// -------------------
// 2. Avoid IPN Failure after switching PayPal email for Product ID
require_once WC()->plugin_path() . '/includes/gateways/paypal/includes/class-wc-gateway-paypal-ipn-handler.php';
class WC_Gateway_Paypal_IPN_Handler_Switch extends WC_Gateway_Paypal_IPN_Handler {
protected function validate_receiver_email( $order, $receiver_email ) {
if ( strcasecmp( trim( $receiver_email ), trim( $this->receiver_email ) ) !== 0 ) {
// ENTER HERE SAME PAYPAL EMAIL USED ABOVE
if ( $receiver_email != 'another-paypal@example.com' ) {
WC_Gateway_Paypal::log( "IPN Response is for another account: {$receiver_email}. Your email is {$this->receiver_email}" );
$order->update_status( 'on-hold', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'woocommerce' ), $receiver_email ) );
exit;
}
}
}
}
new WC_Gateway_Paypal_IPN_Handler_Switch();
Is There a (Reliable) Plugin For That?
If you’d love to code but don’t feel 100% confident with PHP, I decided to look for a reliable plugin that achieves the same result (well, actually it gives you more).
In this case, I recommend the WooCommerce Multiple PayPal Accounts Plugin. On top of sending the whole order total to a different PayPal account based on total, billing country, category, tag, user role, shipping class, currency, you can also split payments between PayPal accounts, keep a commission as a store owner, integrate with WC Vendors and Dokan and much more.
But in case you hate plugins and wish to code (or wish to try that), then keep reading π
I’m looking for the code to switch PayPal accounts during the WooCommerce payment process based on the customer. Specifically, I want to rotate PayPal accounts so that each customer uses a different account when making a payment, with only one payment button visible in the store interface, if possible
Abdo, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
I need the same plugin ..
if available let me know to purchase
Which PayPal plugin are you on?
I’ve been using this snippet for a few years now without problems, thanks so much for this, it has been flawless. However PayPal are not supporting PayPal Standard anymore and woocommerce are replacing it with the PayPal Payments plugin, so this snippet will no longer work. Can you publish an update that works with PayPal Payments?
Please send me a reminder in a few months, as I still use PP standard on this same website and won’t drop it until it keeps working (the new solution is full of bugs).
Here’s the reminder as requested. I am still getting emails from PayPal asking me to move over to their new API code. I can see that the PayPal payments plugin appears a bit buggy but there is a more popular, less buggy plugin here https://en-gb.wordpress.org/plugins/pymntpl-paypal-woocommerce/
I spoke with them about providing a way to use multiple user accounts in one woocommerce setup and they said it was more complex than the paypal standard approach and beyond the scope of the support forums.
Could you help? Otherwise I am going to drop PayPal and just use Stripe which still works.
Thank you Jon. Each plugin is coded differently, especially those that integrate WooCommerce with a payment provider such as PayPal. It’s impossible for me to provide a free solution for each possible PayPal plugin out there, so for now I won’t change this as it still works perfectly on this same website with the PayPal Standard method that comes with WooCommerce.
If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi Rodolfo,
I have no doubt that your “Switch PayPal Account @ WooCommerce Checkout” works on single purchases. Do you know if it will work for WooCommerce Subscriptions / Recurring Payments? With of course Billing Agreements / Reference Transactions for PayPal activated.
Thanks,
Hans
No idea! Please always test on staging
I couldn’t get this to work.
The first error I got, was due to namespacing (
had to be replaced with
).
After I did that, then the page loaded. But when I clicked ‘Proceed to PayPal’, then I get directed to sandbox… And if I click ‘Login’ then I just log in to the Sandbox-PayPal-account – I don’t get redirected to any payment page. It’s like it forgot that I was in the middle of something π
I am using an sandbox-email, I don’t know.
I do find it weird that the API-username, password and signature doesn’t need to be changed, so it matches this new email.
When all has been said, then PayPal’s dashboard has been really flakey to work with.
Thanks for that, I’m not 100% sure, this would require custom troubleshooting
Hello!
Is it possible to use Different PayPal Standard Account For a shipping address @ WooCommerce Checkout?
1 account for EU shipping
1 account for US/Rest of World shipping
Thank you!
Gian Luca
Hey Gian Luca, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
By an amazing coincidence I was working on this problem yesterday but your code has showed that I don’t understand filters properly and I would like your help.
This filter does not appear in the WooCommerce Code Reference.
* https://woocommerce.github.io/code-reference/hooks/hooks.html
* How did you find it?
It does appear here.
* https://hookr.io/filters/woocommerce_paypal_args/
and the definition is
“add_filter(‘woocommerce_paypal_args’, array($this, ‘filter_paypal_args’));”
It seems to have a single parameter. But your code
“function bbloomer_switch_paypal_email_based_product( $paypal_args, $order )”
MAGICALLY knows that $order exists as second parameter. How did you know this and why does it work?
I solved part of this problem. I now understand to find the arguments passed to a filter call you have to look at the “apply_filters” call not the add_filter syntax.
I still don’t know how you found the woocommerce_paypal_args filter because I can’t find it in the documentation.
Nice, good trial and error there! I found that filter by looking at other snippets online and then double checking it still existed by searching through the WooCommerce plugin code.
Hi,
Wow, Works like charm!
Thanks
Ahir
Great!
How do i modify the code to work for a particular / multiple product categories?
Hello Debashish, thanks so much for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Enjoy π
Hello Rodolfo, thanks a lot for your useful tutorials. I would like to achieve something similar to this with the exception that I need not to change paypal basing on product id but basing on checkout price. If below 20$ should use emailpaypal1 if above 20$ I should use emailpaypal2
Is it possible? thanks a lot
Hi Jo, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!