Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AshlinRejo/bb13957f10d8ceed20826bd03538ca0a to your computer and use it in GitHub Desktop.
Save AshlinRejo/bb13957f10d8ceed20826bd03538ca0a to your computer and use it in GitHub Desktop.
Discount rule v2: Remove menu for specific user role
add_action('admin_menu', function (){
$user_role_to_remove = 'administrator'; //Replace the role for which we need to remove menu
$user = (is_user_logged_in()) ? get_user_by('ID', get_current_user_id()) : NULL;
if (!empty($user) && isset($user->roles) && !empty($user->roles)) {
if(in_array($user_role_to_remove, $user->roles)){
global $submenu;
if (isset($submenu['woocommerce'])) {
remove_submenu_page('woocommerce', 'woo_discount_rules');
}
}
}
}, 20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment