mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/78591872/disable-access-to-woocommerce-admin-payments-page-for-specific-users
16 lines
583 B
Text
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();
|
|
}
|
|
}
|