2

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.

please help.

what i need

Hareesh
  • 6,770
  • 4
  • 33
  • 60

2 Answers2

12

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

    }
}
Pat Gilmour
  • 681
  • 9
  • 15
  • You could add slugs for the other WooCommerce admin pages too in case users find a back door by appending the slug. Just add new lines as per the Codex. The slugs for the pages are visible in the 'class-wc-admin-menus.php' file mentioned above. – Pat Gilmour Jun 26 '14 at 17:21
  • how to remove sub menu of woocommerce ( admin.php?page=wc-status ) i use : remove_submenu_page( 'woocommerce', 'wc-status' ); it's not working – Do Xuan Nguyen Sep 14 '16 at 15:34
0

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)

healthybodhi
  • 306
  • 2
  • 4