I'm currently developing a Wordpress Multisite website. I need to have the mainsites payment methods on all subsites (Any user should be able to create their own subsite, thats why I can't do this manually).
On this stackoverflow post they show how to get the payment gateways, but I wasn't able to find any information on how to modify those variables programatically. I have also found this post on how to unset any payment method, but again, they don't say how to set a new payment method or how to modify existing payment methods.
I've tryed this code with no success:
add_filter('woocommerce_available_payment_gateways', 'filter_gateways', 1);
function filter_gateways($gateways){
global $woocommerce;
switch_to_blog( 1 );
$wc_gateways = new WC_Payment_Gateways();
$mainsite_gateways = $wc_gateways->get_available_payment_gateways();
restore_current_blog();
return $mainsite_gateways;
}
Also tried this just to be sure that it didn't work and nothing happened
add_filter('woocommerce_available_payment_gateways', 'filter_gateways', 1, 100);
function filter_gateways($gateways){
global $woocommerce;
switch_to_blog( 1 );
$mainsite_gateways = WC()->payment_gateways->get_available_payment_gateways(); //modified this
restore_current_blog();
return $mainsite_gateways;
}
I have a similar issue with emails. I need the mainsite email address to handle all woocommerce emails using the mainsite email templates...