Woocommerce shop manager role, hide woocommerce menu

I am using a wordpress theme which supports woocommerce,
when adding a user with shop manager role i don’t want to show the woocommerce menu.

Just need the products menu only.

Read More

please help.

what i need

Related posts

Leave a Reply

2 comments

  1. You can use WordPress’s ‘remove_menus()‘ function to do this.

    Store Managers have a capability: ‘manage_woocommerce’

    You can see that they are allowed to see the WooCommerce admin menu here:
    ‘/wp-content/plugins/woocommerce/includes/admin/class-wc-admin-menus.php’

    Look for: $main_page = add_menu_page( __( 'WooCommerce', 'woocommerce' ), __( 'WooCommerce', 'woocommerce' ), 'manage_woocommerce', 'woocommerce' , array( $this, 'settings_page' ), null, '55.5' );

    So much for the theory. To stop this admin menu item from displaying for anyone but an Administrator, add this to your functions.php file or plugin:

    add_action( 'admin_menu', 'remove_menus' );
    function remove_menus(){
    
        // If the current user is not an admin
        if ( !current_user_can('manage_options') ) {
    
            remove_menu_page( 'woocommerce' ); // WooCommerce admin menu slug
    
        }
    }
    
  2. Don’t have the rep points to add a comment, but needs to change the hooked action from:

    add_action( 'admin_menu', 'remove_menus' );
    

    to:

    add_action( 'admin_init', 'remove_menus' );
    

    and then you can do something like:

    function remove_menus(){
    
        // If the current user is not an admin
        if ( !current_user_can('manage_options') ) {
    
            remove_submenu_page('woocommerce', 'wc-status');
    
        }
    }
    

    if you are trying to remove core woocommerce submenu items.

    (responding to Do Xuan Nguyen’s comment)