Are you looking for a way to offer role based payment options in your WooCommerce store? Then read on, as this post aims to provide a custom made solution for you. We will provide a step by step guide on how you can enable or disable a payment gateway by user role.
All WooCommerce store owners need to offer different payment options to different types of customers. There are plenty of reasons why you might want to offer a role based payment method.
For example, you can offer popular online payment options like PayPal to retail customers and additional payment options like invoice, cheque, and cash on delivery for regular wholesalers.
Adding role based payment methods is also a great idea for trusted customers. For example, guest users can make online payments at the time they place an order. This will help you deliver a better, more personalized customer experience and, as a result, help you boost sales.
By default, WooCommerce shows the same payment options for all customers, regardless of the user role. This is why we created this brief tutorial to help you out.
WooCommerce Role Based Payment Methods
By the end of this post, you will be able to disable or enable a payment gateway based on a user role. The easiest way to do this is using a custom code snippet to edit some of WooCommerce’s core files.
This means that you need to install or activate a child theme. It will ensure that the changes you make are not lost during an update. It is incredibly easy to set up because you can install it on your site as a plugin.
Without wasting much time, let us get right into it.
Steps to Enable or Disable Payment Gateway for a Specific User Role
Here are the simple steps you need to follow:
- Log into your WordPress site and access the Dashboard as the admin user.
- From the Dashboard menu, click on Appearance Menu > Theme Editor Menu. When the Theme Editor page is opened, look for the theme functions file to add the function to enable PayPal for admin only.
- Add the following code to the php file:
function njengah_paypal_enable_manager( $available_gateways ) {
if ( isset( $available_gateways[‘paypal’] ) && ! current_user_can( ‘manage_woocommerce’ ) ) {
unset( $available_gateways[‘paypal’] );
}
return $available_gateways;
}
[/php]
- Alternatively, if you want to disable Paypal for the admin, add the following code to the php file:
function njengah_paypal_disable_manager( $available_gateways ) {
if ( isset( $available_gateways[‘paypal’] ) && current_user_can( ‘manage_woocommerce’ ) ) {
unset( $available_gateways[‘paypal’] );
}
return $available_gateways;
} [/php]
In the above example, we checked for the “PayPal” option. Here are the keywords for the other payment options:
- Direct Bank Transfer: bacs
- Check Payment: cheque
- PayPal: paypal
- Cash on Delivery: cod
Wrapping Up
In this brief guide, you have seen how it is very easy to offer role passed payment options in your WooCommerce store. However, you should be careful when editing the functions file. If you make any mistake, a critical error will be displayed.
If you are not familiar with coding, we recommend using a plugin like Payment Gateways by User Roles for WooCommerce. But it is important to note that you need to use their pro version to get the best out of it.
Similar Articles
- How to Remove Checkout Button WooCommerce
- How to Remove Phone Number Field From Checkout WooCommerce
- How to Create WooCommerce Payment Gateway
- How to Hide Tags In Storefront Theme WooCommerce
- How to Fulfill Orders in WooCommerce
- How to Remove Country Field From Checkout WooCommerce
- How to Create WooCommerce Custom My Account Page
- WooCommerce Redirect Users After Registration by Roles
- How to Get Current User Role in WordPress & Display Roles
- How to Hide Admin Bar for WooCommerce Customers or By User Roles
- How to Hide a Product in WooCommerce or Hide Products by Category or Roles
- How to Create WordPress Custom User Roles
- How to Add Custom WooCommerce Payment Icons Checkout Page
- What is the Best Payment Gateway for WooCommerce
- How to Set Up WooCommerce Cart and Checkout on the Same Page
- How to Hide Category From Shop Page WooCommerce
- How to Redirect On Refresh WordPress Page » Detect Page Refresh PHP
- How to Add WooCommerce Shopping Cart Icon In Menu
- How to Style WooCommerce Checkout Page
- How to Change WooCommerce Storefront Layout