Is it possible to filter available payment methods to certain user roles just using the WooCommerce configuration? Without adding anything to any template file I mean. What I want to achieve is to give the possibility to pay with credit card only to certain users.
2 Answers
It is not possible by WooCommerce default configuration.
You have to install below plugin.
https://codecanyon.net/item/woocommerce-role-based-payment-shipping-methods/18953727
or programmatically, you can refer below link.
https://businessbloomer.com/disable-payment-gateway-specific-user-role-woocommerce/
You can use following:
add_filter('woocommerce_available_payment_gateways', 'filter_gateways', 1);
function filter_gateways($gateways)
{
$current_user = wp_get_current_user();
$role = $current_user->roles;
global $woocommerce;
/* add your user role in condition and payment method which you need to unset*/
if ($role[0] == 'administrator') {
unset($gateways['cod']);
}
return $gateways;
}