Woocommerce – Disable Fee Strategies Based mostly on Person Roles

Typically it occurs that you should disable Woocommerce fee strategies based mostly on consumer roles. For instance, you wish to disguise Money on Supply methodology for logged-out customers. Otherwise you wish to disguise BACS methodology for all roles besides clients and store managers. And better of all – you are able to do it with none fancy plugin.

So, if that is one thing you’re in search of then check out the tutorial I made you.

Tips on how to disable Woocommerce BACS Fee methodology for chosen consumer roles?

On this first instance I’m going to cover Direct Financial institution Switch (BACS) fee methodology for all consumer roles besides clients, store managers and directors. Simply seize this code right here under and paste it to your theme’s features.php file or higher yer, use Code Snippets plugin for it. This manner you’ll not lose all of the modifications throughout your subsequent theme swap.

// Allow BACS fee methodology for patrons, store managers and directors

perform bacs_payments( $available_payment_gateways ) {
$consumer = wp_get_current_user();
$allowed_roles = array('buyer', 'administrator', 'shop_manager');
	if (!array_intersect($allowed_roles, $user->roles )) {
	if (isset($available_payment_gateways['bacs'])) {
		unset($available_payment_gateways['bacs']);
}
}
return $available_payment_gateways;
}
add_filter('woocommerce_available_payment_gateways', 'bacs_payments', 90, 1); 

Couple of issues to level out:

  • ‘buyer’, ‘administrator’, ‘shop_manager’ are the consumer roles I would like the BACS to be energetic. Change them in response to your wants
  • ‘bacs’ is the Fee methodology I have to be energetic for these consumer position. Change it in response to your wants

Tips on how to discover out Woocommerce fee methodology slugs?

Each fee methodology makes use of its personal slugs. So, if you wish to change the fee methodology identify within the code and also you don’t know the slug, then go to Woocommerce >> Settings >> Fee and open up a fee methodology. Now check out the URL in your browser. Whether it is https://yoursite.com/wp-admin/admin.php?web page=wc-settings&tab=checkout&part=bacs then the bacs is the slug you want.

If the tackle is https://yoursite.com/wp-admin/admin.php?web page=wc-settings&tab=checkout&part=paypal and you should use the Paypal methodology, then final a part of the URL (paypal) is the one you want.

Tips on how to disable Woocommerce Money on Supply fee methodology for chosen consumer roles?

Subsequent situation: I wish to disable Money on supply for logged-out customers and subscriber roles. Due to this fact, I paste this snippet in my Code Snippets or features.php file.

// Disable Money on supply for logged out customers and subscriber roles

perform disable_cod( $available_gateways ) {
    if ( isset($available_gateways['cod']) && (current_user_can('subscriber') || ! is_user_logged_in()) ) {
         unset($available_gateways['cod']);
     }
     return $available_gateways;
}
add_filter('woocommerce_available_payment_gateways', 'disable_cod', 99, 1);

Couple of issues to level out:

  • ‘subscriber’ is the consumer position I would like the COD to be disabled. Change it in response to your wants
  • is_user_logged_in means “for logged-out customers”.
  • ‘cod’ is the fee methodology I have to be disabled for the subscriber consumer position. Change it in response to your wants

Tips on how to disguise a number of Woocommerce Fee strategies for chosen consumer roles?

On this instance I’m going to cover a number of Woocommerce fee strategies (Paypal, Cheque and COD) for Store Supervisor consumer position. If you wish to do the identical then use this code right here under.

// Cover Paypal, Examine funds and COD for store supervisor position

add_filter('woocommerce_available_payment_gateways', 'shopmanager_payments', 1);
  perform shopmanager_payments($gateways)
  {
      $current_user = wp_get_current_user();
      $position = $current_user->roles;
      international $woocommerce;
      /* add your consumer position in situation and fee methodology which you should unset*/
      if ($position[0] == 'shop_manager') {
      	unset($gateways['paypal']);
	unset($gateways['cheque']);
	unset($gateways['cod']);
      }
      return $gateways;
  }

Couple of issues to level out:

  • ‘shop_manager’ is the consumer position I would like these fee mehtods to be disabled. Change it in response to your wants
  • unset($gateways[‘paypal’]); – this disables Paypal fee methodology. Change it in response to your wants
  • unset($gateways[‘cheque’]); – this disables Woocommerce Cheque fee methodology. Change it in response to your wants
  • unset($gateways[‘cod’]); – this disables Woocommerce Money on Supply fee methodology. Change it in response to your wants

Additionally, should you use your individual customized fee strategies then change the slug above. For instance, should you use Stripe fee methodology and it has a slug “stripe” then add this line unset($gateways[‘stripe]);

Video: Woocommerce – Disable Fee Strategies Based mostly on Person Roles

Helpful Woocommerce tutorials

  • Tips on how to promote tickets with Woocommerce?

  • Kadence WooExtras Plugin – Full Overview

  • Tips on how to Mechanically Delete Woocommerce Photographs After Deleting a Product?

  • 12 helpful Woocommerce snippets & hacks

  • Tips on how to Present Woocommerce Variations as Single Merchandise?

Leave a Comment

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

Shopping Cart
Scroll to Top