How to Disable Payment Gateways For Some Users

Running a WooCommerce store can be a daunting task. It requires constantly changing configurations and optimizing the site with the best possible user experience. As an eCommerce owner, you may need to disable specific payment gateways. 

The need to disable payment gateways can depend on multiple factors, including the inability to deliver products to certain users or simply restricting users from making purchases.

In this tutorial, we will go through the critical steps on how to disable payment gateways for some user roles in WooCommerce. For this purpose, we will use the OptimizeForm Core —  a simple to use plugin that lets you access different functionalities using modules.

How to disable payment gateway for a specific role using code

If you are not into plugins, then you can also use code to disable payment gateways. However, we do not suggest using code if you are not comfortable using it — as it can bring more complexity to the process and hamper the basic functionality of your site.

If you are comfortable with the process, you can use the following code to disable the payment gateway.

 * Disable Payment Gateway for a Specific User Role | WooCommerce
add_filter( 'woocommerce_available_payment_gateways', 'payment_gateway_disable_private' );
 function payment_gateway_disable_private( $available_gateways ) {
    $user = wp_get_current_user();
    if ( isset( $available_gateways['cod'] ) && !is_user_logged_in() || isset( $available_gateways['cod'] ) && in_array('subscriber', $user->roles)  ) {
        unset( $available_gateways['cod'] );
   return $available_gateways;

The above code disables the “Cash on delivery” option for users that are not logged in. You can similarly edit the above code and use it according to your requirement.

But, as we said earlier, doing it with code can be tricky and can lead to problems if not done correctly.

That’s why we suggest using the OptimizeForm Core plugin to disable payment gateways. Not only can you make changes quickly, but you can also revert them when needed.

How to Disable Payment Gateways For Some Users

In this section, we will be using the OptimizeForm Core plugin. As already mentioned, code can work too, but it is tricky and can lead to problems down the road. To solve the problem we will use OptimizeForm plugin

Let’s get started with the steps below.

1.  Install OptimizeForm Core Plugin

To get started, you need to install the OptimizeForm Core plugin. As it is a paid product, you need to get the license before you can use it. Once you acquire the plugin, you need to download the plugin to the computer.

From there, you need to login into your website backend and then install the plugin. To do so, go to Plugins >> Add New. 

Now upload the plugin by clicking the “Upload Plugin.” If the plugin files are okay, the plugin will get installed. Finally, click on Activate to enable the plugin on your site. 

2. Activate OptimizeForm Shipping and Payments Module

OptimizeForm Core comes with a bunch of modules. In our case, we need the OptimizeForm Shipping and Payments Module.

To activate it, you need to go to OptimizeForm and then click on Modules.

Once there, you need to find the module and turn it on, as shown below.

Once activated, you will see that you can manage the plugin. You can click on manage to go to the options, or refresh the page to see a new “Shipping and Platform” menu option appear within the plugin.

3. Navigate to Payments Gateways

From Shipping and Payments, you can move to Payment Gateways, where you get the option to change things.

To move to the payments gateway, you need to click on “Shipping and Payments.”

4. Click Add Restriction

There you will find the option to add restrictions. To add restriction, you need to click on the “Add Restriction” option, opening up a new window.

5. Disable Payment Gateway By User Role

Here, you can find three two fields; one shows the excluded option and the ability to add conditions.

So, if you want to add a restriction for wholesale buyers not to use Paypal, you can do so by adding “Paypal” to exclude gateways. Now move to “Add Condition,” and from there, you can change to Customer Role and then choose the customer role that you want to restrict.

You will also notice that the condition can be set to “Is” and “is not.” So double-check the condition before making it live.

Caption: Image showing the ability to restrict payment gateways to wholesale customers


As you can see, you have two options to disable payments gateways for some users. Businesses can opt to disable payment gateways as they want. However, running an eCommerce site can be a daunting task — and as you get more users, enabling or disabling the payment gateways for users can mean investing a lot of time if you intend to do it with code.

The OptimizeForm Core plugin is an optimal way to handle payment gateways for users as you can quickly enable or disable restrictions when you see fit.


Welcome to the AovUp blog, where we discuss all things WooCommerce. I hope we can help you achieve something today...

Leave a Reply

Your email address will not be published. Required fields are marked *

We – and our partners – use cookies to deliver our services and to show you ads. By using our website, you agree to the use of cookies as described in our Cookie Policy