Menu Close

Enable/Disable Payment Gateway for a Specific User Role

codeamend
You may want to disable payment gateways depending on the user role or user capability. For example, you may want to disable PayPal for “user role: shop_manager” or enable a specific gateway for “user role: customer”. All you need is pasting the following code in your functions.php
Disable Payment Gateway for a Specific User Role – WooCommerce Checkout
add_filter( 'woocommerce_available_payment_gateways', codeamend_paypal_disable_manager);
  
function codeamend_paypal_disable_manager( $available_gateways ) {
   if ( isset( $available_gateways['paypal'] ) && current_user_can( 'manage_woocommerce' ) ) {
      unset( $available_gateways['paypal'] );
   }
   return $available_gateways;
}
 
Enable Payment Gateway for a Specific User Role – WooCommerce Checkout
add_filter( 'woocommerce_available_payment_gateways', codeamend_paypal_enable_manager);
  
function codeamend_paypal_enable_manager( $available_gateways ) {
   if ( isset( $available_gateways['paypal'] ) && ! current_user_can( 'manage_woocommerce' ) ) {
      unset( $available_gateways['paypal'] );
   }
   return $available_gateways;
}
 
Note to find payment gateway slug: When you hover the payment gateway name in Woocommerce payment settings you can find refer: https://example.com/wp-admin/admin.php?page=wc-settings&tab=checkout&section=paypal

Share

Posted in WooCommerce

You can also read...

Leave a Reply

Your email address will not be published.