Skip to content

Instantly share code, notes, and snippets.

@lukecav
Last active November 11, 2022 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukecav/18176ae543d33dee12b61997904b6bc0 to your computer and use it in GitHub Desktop.
Save lukecav/18176ae543d33dee12b61997904b6bc0 to your computer and use it in GitHub Desktop.
Remove the Limit Orders aettings tab for Shop Managers in WooCommerce
add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 );
function remove_woocommerce_setting_tabs( $array ) {
// Declare the tabs we want to hide
$tabs_to_hide = array(
'limit-orders' => 'Order Limiting',
);
// Get the current user
$user = wp_get_current_user();
// Check if user is a shop_manager
if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {
// Remove the tabs we want to hide from the array
$array = array_diff_key($array, $tabs_to_hide);
// Loop through the tabs we want to remove and hook into their settings action
foreach($tabs_to_hide as $tabs => $tab_title) {
add_action( 'woocommerce_settings_' . $tabs , 'redirect_from_tab_page');
}
}
return $array;
}
function redirect_from_tab_page() {
// Get the Admin URL and then redirect to it
$admin_url = get_admin_url();
wp_redirect($admin_url);
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment