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:

Payment gateways by user roles in WooCommerce
Restricting the “Cash on delivery” payment method for both subscribers and contributors.

Needless to say, with the help of Simple Conditional Shipping and Payments, you can also:

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( ! current_user_can( 'administrator' ) ) {

If you have any questions, feel free to ask them in the comments section.

Misha Rudrastyh

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

Follow me on X