How to set up and assign payments to multiple Stripe accounts in WooCommerce

Do you remember that we already figured out how to set up multiple PayPal accounts in WooCommerce? Well, by popular demand, today we are going to see how to set up multiple Stripe accounts in WooCommerce.

Stripe has become a really attractive payment platform, and thanks to free plugins like the one proposed in the WooCommerce installation itself, configuring it is as simple as adding the secret key and the publishable key, production or tests, in the WooCommerce settings

But there is only one field, general for all transactions in the online store, not one per user.

Now fortunately there are ways that we can switch Stripe accounts, either programmatically, under what conditions, by product ID, etc.

How to map different Stripe accounts based on product with code

In this code example we are going to see how to use multiple Stripe accounts conditionally, if there is a specific product ID in the cart. The code looks for a product ID in the order and switches Stripe keys if it matches that ID.

This only works when there is only 1 product, so you may have to prevent more than 1 product from being added to the cart, additionally. This can be done easily in the inventory tab of the product data

function ayudawp_id_producto( $id ) {

$product_cart_id = WC()->cart->generate_cart_id( $id );

$in_cart = WC()-<cart->find_product_in_cart( $product_cart_id );

if ( $in_cart ) return true;

return false;

}

add_filter( 'wc_stripe_params', 'ayudawp_stripe_clave_publicable', 9999 );

function ayudawp_stripe_clave_publicable( $params ) {

if ( ! ayudawp_id_producto( 12345 ) ) return $params;

$params[ 'key' ] = 'pk_live_................';

return $params;

}

add_filter( 'wc_stripe_payment_request_params', 'clasesordenador_clave_publicable_condicional', 9999 );

function ayudawp_clave_publicable_condicional( $params ) {

if ( ! clasesordenador_id_producto( 12345 ) ) return $params;

$params[ 'stripe' ][ 'key' ] = 'pk_live_................';

return $params;

}

add_filter( 'woocommerce_stripe_request_headers', 'clasesordenador_clave_privada_condicional', 9999 );

function ayudawp_clave_privada_condicional( $headers_args ) {

if ( ! ayudawp_id_producto( 12345 ) ) return $headers_args;

$headers_args[ 'Authorization' ] = 'Basic ' . base64_encode( 'sk_live_..........' . ':' );

return $headers_args;

}

You must add the code to the functions.php file of the active theme or to a customization plugin, as you prefer.

Different Stripe account per seller

Another, more advanced possibility is to use a multi-vendor system, in which each vendor authorizes payments from the marketplace through Stripe Connect and automatic payments to their respective account.

This is easy to configure with plugins such as WooCommerce MultiVendor / MarketPlace, where you must initially connect the Stripe Connect gateway as administrator and select it as the gateway for payments to sellers in the plugin settings.

In addition, each seller must connect through Stripe Connect with their own Stripe account so that automatic payments can be activated.

This can be done in the administration area or on the page of your user account.

Once the above is done, each seller will automatically receive payments, once the previously defined commission has been satisfied, in their own Stripe account, automatically.

As you have seen it is not only possible to use multiple Stripe accounts in WooCommerce but there are several ways to address this need, I hope I have helped you.

Date update on 2021-02-16. Date published on 2021-02-16. Category: Computer class Author: Oscar olg Fuente: ayudawp