How to Set Up WooCommerce Role Based Payment Methods

WooCommerce Role Based Payment MethodsAre 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:

  1. Log into your WordPress site and access the Dashboard as the admin user.
  2. 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.
  3. Add the following code to the php file:
add_filter( 'woocommerce_available_payment_gateways', 'njengah_paypal_enable_manager' );
  function njengah_paypal_enable_manager( $available_gateways ) {
   if ( isset( $available_gateways['paypal'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
      unset( $available_gateways['paypal'] );
   } 
   return $available_gateways;
}
  1. Alternatively, if you want to disable Paypal for the admin, add the following code to the php file:
add_filter( 'woocommerce_available_payment_gateways', 'njengah_paypal_disable_manager' );
  function njengah_paypal_disable_manager( $available_gateways ) {
   if ( isset( $available_gateways['paypal'] ) && current_user_can( 'manage_woocommerce' ) ) {
      unset( $available_gateways['paypal'] );
   } 
   return $available_gateways;
}

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


Customer Reviews

NJENGAH

Customer Reviews

Jeffrey Todd 04/07/2020

Exceptional Plugin & Service

I'm in the process of building my new website, and I had a question about changing some text within the WooCommerce plugin. I was spinning my wheels trying to figure it out. Joe reached back and worked with me - going above and beyond! - until I fully understood how to effectively change what I wanted. How can you ask for more than that? I highly recommend WooCommerce (and Joe!), the plugin and service are exceptional!
-Jeffrey Todd (MyLifeChart.com)