Skip to content

Instantly share code, notes, and snippets.

@kartick14
Created April 30, 2018 09:42
Show Gist options
  • Save kartick14/041c632962da2e6634fdb14f8c46339f to your computer and use it in GitHub Desktop.
Save kartick14/041c632962da2e6634fdb14f8c46339f to your computer and use it in GitHub Desktop.
Enable/Disable Payment Gateway for a Specific User Role
/**
* @snippet Enable Payment Gateway for a Specific User Role | WooCommerce
*/
function custom_paypal_enable_manager( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['paypal'] ) && !current_user_can('shop_manager') ) {
unset( $available_gateways['paypal'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'custom_paypal_enable_manager' );
/**
* @snippet Disable Payment Gateway for a Specific User Role | WooCommerce
*/
function custom_paypal_disable_manager( $available_gateways ) {
global $woocommerce;
if ( isset( $available_gateways['paypal'] ) && current_user_can('shop_manager') ) {
unset( $available_gateways['paypal'] );
}
return $available_gateways;
}
add_filter( 'woocommerce_available_payment_gateways', 'custom_paypal_disable_manager' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment