Code-Snippets-Functions/Execute a function on a child site/WooCommerce/disable-access-to-admin-payments-page-for-specific-users.txt

16 lines
583 B
Text

add_action( 'woocommerce_init', 'role_based_redirect' );
function role_based_redirect() {
global $pagenow, $current_user;
// Define allowed users below
$non_allowed_users = array("abc", "afi", "asd");
// Targetting WooCommerce Admin Payments page
if ( $pagenow === 'admin.php' && isset($_GET['page'],$_GET['tab'])
&& $_GET['page'] === 'wc-settings' && $_GET['tab'] === 'checkout'
&& in_array( strtolower($current_user->user_login), $non_allowed_users ) )
{
wp_redirect( admin_url( 'admin.php?page=wc-settings' ) );
exit();
}
}