I'm trying to add another PayPal email address into Woocommerce if the customer is within a certain role, in this case a Wholesale Customer. Woocommerce by default only allows you to setup one PayPal account but I have been able to find the woocommerce_paypal_arg
s function to change the arguments which are sent to PayPal. I can see the business field is responsible for holding the email address the payments are sent to.
I've got the code below which should intercept this and change it if the user is a wholesale_customer.
The question is.. How secure is this? Is there a better method of doing what I want?
add_filter( 'woocommerce_paypal_args', 'woocommerce_paypal_args', 10, 2 );
function woocommerce_paypal_args( $paypal_args, $order ) {
//Get the customer ID
$user_id = $order->get_user_id();
// Get the user data
$user_data = get_userdata( $customer_id );
// Adding an additional recipient for a custom user role
if ( in_array( 'wholesale_customer', $user_data->roles ) )
$paypal_args['business'] = '[email protected]';
return $paypal_args;
}
I can tell you from experience building and modding WooCommerce gateways that this is both a perfectly secure and reasonable way of achieving this using your current plugin. That said... use some brackets when writing an if statement... this isn't python.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With