When managing an online store with WooCommerce, customization is key to providing your customers with an exceptional shopping experience. An effective way to achieve this is by adjusting the available payment options based on user role or status. In this article, we will show you how to disable or enable specific payment gateways for user roles or registered users in your WooCommerce store. These strategies not only enhance the shopping experience but can also be tailored to your business objectives, such as encouraging user registration or offering exclusive benefits to certain roles.

Disabling Payment Gateways for a Specific User Role in WooCommerce:
Sometimes, you may wish to disable certain payment gateways for a specific user role. For example, you might want to disable the PayPal gateway only for ‘Editors’. Below, we show you how to do this:
function filtrar_pasarelas_pago( $available_gateways ) {
$user = wp_get_current_user();
// Desactivar PayPal para editores
if ( in_array( 'editor', $user->roles ) && isset( $available_gateways['paypal'] ) ) {
unset( $available_gateways['paypal'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'filtrar_pasarelas_pago' );
Enabling Payment Gateways Only for a Specific User Role:
In other cases, you may want to allow only certain user roles to use a specific payment gateway. For example, you can enable the BACS (bank transfer) gateway only for ‘Authors’. Here is how to do it:
function filtrar_pasarelas_pago( $available_gateways ) {
$user = wp_get_current_user();
// Si el usuario no es un autor, desactivamos BACS
if ( !in_array( 'author', $user->roles ) && isset( $available_gateways['bacs'] ) ) {
unset( $available_gateways['bacs'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'filtrar_pasarelas_pago' );
Enabling Payment Gateways Only for Registered Users:
You can also offer an exclusive payment gateway for registered users. If you want only registered users to be able to use PayPal, follow these steps:
function pasarela_exclusiva_registrados( $available_gateways ) {
// Si el usuario no está registrado, desactivamos PayPal
if ( !is_user_logged_in() && isset( $available_gateways['paypal'] ) ) {
unset( $available_gateways['paypal'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'pasarela_exclusiva_registrados' );
How to Add the Above Code to WooCommerce and WordPress:
Of course, here is a brief guide on how to add the provided code to your WooCommerce store:
Step 1: Access the WordPress Admin Dashboard:
Log in to your WordPress website using administrator credentials.
Step 2: Open the Theme Editor or a Customization Plugin:
Depending on your preference and setup, you can choose between two methods to add the code: through the theme editor or a customization plugin.
- Theme Editor (Recommended if you are using a custom theme):
- In the WordPress admin dashboard, navigate to “Appearance” and select “Editor”.
- In the right sidebar, you will see a list of files related to your active theme. Look for “functions.php” and click on it.
- Customization Plugin (Recommended if you are using a pre-designed theme):
- Install and activate a customization plugin, such as “Code Snippets”. You can do this from “Plugins” > “Add New” and search for the desired plugin.
- Once activated, go to “Snippets” or the equivalent section of the plugin.
Step 3: Add the Code:
In the “functions.php” file or in the “Snippets” section of the customization plugin, you can copy and paste the code provided in the article according to your needs. Ensure the code is placed in an appropriate location within the file or in the plugin interface.
Step 4: Save the Changes:
After pasting the code, make sure to save the changes. In the theme editor, there is usually an “Update File” button. In the customization plugin, save the snippet.
Step 5: Verify Functionality:
Once you have saved the changes, verify that the code is working correctly in your WooCommerce store. Perform tests with different user roles or scenarios based on the code you have added.
That’s it! You have successfully customized the payment gateways in your WooCommerce store. Remember that it is important to back up your website before making significant changes to the code, and if you have any questions or issues, feel free to contact me.
Conclusion:
Customizing payment options based on user role or status is a smart strategy to optimize the shopping experience in your WooCommerce store. Additionally, these customizations can help you achieve your business objectives, such as encouraging user registration or providing exclusive advantages to certain roles. With these examples and tips, you can adapt WooCommerce to the specific needs of your store and your customers, offering a unique and attractive shopping experience. Customize your payment gateways and take your online store to the next level!
Do you need help with a web project?
Do you need help with a web project? Don't hesitate to contact me. I develop complete and customized solutions with WordPress and PHP, using modern tools and processes, HTML, CSS, SCSS, PHP, JavaScript, Bootstrap, and more. Ready? Send me a message and let's talk about your web project!
