Remove General Tab and Plugin Tab in Settings in Woocommerce

So it turns out that because of the way the WC settings page is built, that you can’t unset the general screen. The tab, sure, but clicking on the WooCommerce settings in the dashboard submenu will always load the General settings, even if the tab is missing. So I wrote two different functions to remove all of it and the second function just so happens to allow us to also remove the Order Status screen. (Not sure about the tab though, but you can hide that with CSS because we’ll already be making sure users can’t navigate to that panel if they’re lowly shipping_managers.)

add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 );
function remove_woocommerce_setting_tabs( $array ) {
    global $current_user;
    if( in_array( 'shipping_manager', $current_user->roles ) ) {
        unset( $array[ 'general' ] );
        unset( $array[ 'products' ] );
        unset( $array[ 'tax' ] );
        unset( $array[ 'checkout' ] );
        unset( $array[ 'account' ] );
        unset( $array[ 'email' ] );
        unset( $array[ 'integration' ] );
        unset( $array[ 'advanced' ] );
        echo '<script>jQuery( document ).ready( function($) { $( \'[href="' . admin_url() . '/edit.php?post_type= wc_order_status"]\' ).hide(); } );</script>';
    }
    return $array;
}
add_action( 'admin_init', 'redirect_from_settings_screen' );
function redirect_from_settings_screen() {
    global $pagenow;
    global $current_user;
    if( in_array( 'shipping_manager', $current_user->roles ) ) {
        if( $pagenow == 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] == 'wc-settings' && !isset( $_GET['tab'] ) ) {
            wp_redirect( admin_url( '/admin.php?page=wc-settings&tab=shipping' ) );
            exit;
        }
        if( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'wc_order_status' ) {
            wp_redirect( admin_url( '/admin.php?page=wc-settings&tab=shipping' ) );
            exit;
        }
    }
}

So here’s a breakdown, the first function allow us to remove all of the WC Settings Tabs, including General. Works like a treat except for the fact that navigating to the WC Settings screen will, by default, load the General settings fields. So that’s no good. But, everything else is gone and the shipping tab is visible and works perfectly.

Next we have a function to redirect access to the General Settings screen admin.php?page=wc-settings to route people to admin.php?page=wc-settings&tab=shipping.

Then I add on a second check to see if $pagenow is on the Order Status screen, check for the post_type and if it’s wc_order_status and if it is, redirect it to Shipping again.

Now, the first function removes the tabs for all those different settings panels, but a user could technically still access the URLs if they know them. So you could repeat the set-up of the General -> Shipping redirect, or do it as an array of tabs and make sure that even manual attempts to access the other tabs reroute to Shipping.

NOTE

I don’t have a shipping_manager user role to test with so hopefully that won’t pose any problems.