I am trying to change the PayPal address that Woocommerce uses, depending on what page they are on. I only have 5 products at the moment, and all 5 need to use a different P
I've checked and found out that woocommerce_paypal_args
has two arguments, the settings and the order. So based on the order, we can check what product it has and use the appropriate email.
add_filter( 'woocommerce_paypal_args' , 'custom_override_paypal_email', 10, 2 );
function custom_override_paypal_email( $paypal_args, $order ) {
foreach ( $order->get_items() as $item ) {
switch( $item['product_id'] ) {
case 561:
$paypal_args['business'] = 'paypalemail1@domain.com';
break;
case 562:
$paypal_args['business'] = 'paypalemail2@domain.com';
break;
}
}
return $paypal_args;
}
please take note that you have to make sure that there can only be one item on the cart. If there are more than 1 product in the cart, this will use the last found product in the foreach
loop. The code above is just for guidance, please change accordingly.