Skip Navigation

[Resolved] Removing access to WooCommerce Settings for a Custom User Role

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a custom user role that has access to the WooCommerce admin menu. I would like to remove the "Settings" and "Extensions" submenu items from the WooCommerce admin menu for this user role.

Solution: Add the following code to your functions.php file:

add_action( 'admin_menu', 'remove_menu_pages', 999);
function remove_menu_pages() {
  global $current_user;
  
  $user_roles = $current_user->roles;
  $user_role = array_shift($user_roles);
  if($user_role == "user-role-slug") {
    $remove_submenu = remove_submenu_page('woocommerce', 'wc-settings');
    $remove_submenu = remove_submenu_page('woocommerce', 'wc-addons');
  }
}

Edit "user-role-slug" to use the proper slug for your custom user role, and add or remove $remove_submenu lines to remove the desired page submenus. The slugs for each page can be found in wp-admin URLs as shown in the attached screenshot below.

Relevant Documentation: https://codex.wordpress.org/Function_Reference/remove_submenu_page

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 7 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#523132
MCfunctions.jpg

I am trying to: Remove access to Woocommerce settings for a custom role define as "Reception"

I visited the wordpress dashboard as the user, but they still have access to "Settings" under woocommerce menu.

I tried using the following code inserted into my functions.php file but it doesn't work. I tried the code with both 'woocommerce_settings' and 'wc-settings' in the code. Still doesn't work.

add_action( 'admin_menu', 'remove_menu_pages', 999);
function remove_menu_pages() {
global $current_user;
 
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if($user_role == "Reception") {
$remove_submenu = remove_submenu_page('woocommerce', 'woocommerce_settings');
}
}
#523186

Hi, if you go to Toolset > Access Control, then click Custom roles and edit your Reception role, you can find a WooCommerce tab here. Inside this tab, you can uncheck "Manage Settings". This will remove the WooCommerce menu item from the admin area for this user type. Is this what you're trying to do, or are you trying to remove only the settings submenu?

#523189
WooMenu.png

I would like to remove only the "Settings" submenu within WooCommerce but leave access to the other submenus.

Thanks

#523197

Okay, then try "reception" instead of "Reception" and "wc-settings" as the page slug:

if($user_role == "reception") {
  $remove_submenu = remove_submenu_page('woocommerce', 'wc-settings');
}

This works for Reception user role in my local instance, but it may also depend on the permissions you inherited when you created the Reception role. If you run into problems, let me know and I'll take another look.

#523205

That worked, thanks!! If I wanted to also remove access to "Extensions" submenu under Woocommerce, what would I need to do?

#523210
extensions.png

You can copy and paste the remove_submenu line and change out the page slug for any submenu page (see screenshot for location of slug).

$remove_submenu = remove_submenu_page('woocommerce', 'wc-settings');
$remove_submenu = remove_submenu_page('woocommerce', 'wc-addons');