How to Configure Payment Gateways by User Roles
In this tutorial, I will show you how you can configure WooCommerce role-based payment methods. In other words, how you can enable or disable specific payment methods in your store depending on a user role, for example, to restrict the use of “Cash on delivery” for the “Subscriber” role or allow using some payment methods with a discounted price for “Premium customers”.
As usual, I will show you both plugin and programmatic approaches.
Configuring WooCommerce Role-Based Payment Methods Using a Plugin
Simple Conditional Shipping and Payments for WooCommerce is the recommended plugin we will use in this chapter of the tutorial.
The plugin allows you to easily configure WooCommerce role-based methods (both payment and shipping methods).
All you need to do is go to WooCommerce > Settings > Conditions > Payment conditions and click the “Add payment condition” button. Here is the configuration of my condition where I restrict a specific payment method for two different user roles:

Needless to say, with the help of Simple Conditional Shipping and Payments, you can also:
- Create as many conditional rules as you need; you can even allow different payment gateways for different user roles (“Payment method 1” for “Subscriber”, “Payment method 2” for “Customer”, and so on).
- Combine different conditions; for example, let’s say that your conditional rules should also not apply for specific countries.
- The plugin is tested and works for any WooCommerce theme, for both classic and block checkouts.
- Custom user roles created with other plugins are also supported.
- The same goes for custom payment gateways (WooPayments included).
However, if you prefer a programmatic approach, continue reading further.
Setting Up Payment Gateways by User Roles Programmatically
All the code below is based on the woocommerce_available_payment_gateways filter hook and can be inserted into your current or child theme functions.php file or a custom plugin; you can read more about using code snippets here.
Let’s implement the same example – disabling the “Cash on delivery” payment gateway for “Subscriber” and “Contributor” user roles:
/**
* @snippet Configure Payment Gateways by User Roles in WooCommerce
* @author Misha Rudrastyh
* @url https://rudrastyh.com/woocommerce/disable-payment-gateway-by-user-role.html
*/
add_filter( 'woocommerce_available_payment_gateways', 'rudr_turn_off_cod' );
function rudr_turn_off_cod( $available_gateways ) {
if( current_user_can( 'subscriber' ) || current_user_can( 'contributor' ) ) {
if ( isset( $available_gateways[ 'cod' ] ) ) {
unset( $available_gateways[ 'cod' ] );
}
// if you need to disable multiple payment gateways just add similar code
// if ( isset( $available_gateways[ 'payment_gateway_2' ] ) ) {
// unset( $available_gateways[ 'payment_gateway_2' ] );
// }
}
return $available_gateways;
}Some notes related to the code snippet:
- If you don’t know where to get a user role slug, remember that there are default user roles, like
subscriber,author,contributor,editorandadministratorand there are a couple of default roles in WooCommerce too –customerandshop_manager. - What about a payment gateway ID? How to get it? If you are uncomfortable with inspecting source code in your browser, I think the best way is to add a payment gateway ID column.
- The
current_user_can()function doesn’t accept an array of roles, which means if you want to disable a payment method for multiple user roles, you can condition it likecurrent_user_can( 'subscriber' ) || current_user_can( 'author' ). - If, on the other hand, you would like to disable a specific payment gateway for all user roles except a specific one, you can use a condition like this:
if( ! current_user_can( 'administrator' ) ) {If you have any questions, feel free to ask them in the comments section.
Misha Rudrastyh
Hey guys and welcome to my website. For more than 15 years I've been doing my best to share with you some superb WordPress guides and tips for free.
Need some developer help? Contact me
Hey Misha,
first of all, thanks for your blog here, always enjoy your Woocommerce tricks and filters ;-) helps us a lot.
Regarding disable/ enable payment Gateways: Would be great if that could be turned of for specific user id´s instead of the complete role.
This wpuld be helpfull, because in our case we just have 2 roles enabled for our customers, so disablind this by role is not an option.
Hey,
Thank you! I am very glad to hear that! ;)
It can be done with the following condition:
if( 123 === get_current_user_id() ) {For multiple users:
if( in_array( get_current_user_id(), array( 1, 2 ) ) ) {Fyi guys, this feature is now also available in the plugin.