plugins – Hide fields in woocommerce settings

Question

Am trying to hide some fields on the woocommerce settings page, for example hide the currency options on the general tab.

I was able to hide the whole tab by adding this snippet:

add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 );
function remove_woocommerce_setting_tabs( $array ) {
    $tabs_to_hide = array(
        'tax' => 'Tax',
        'checkout' => 'Checkout',
        'email' => 'Emails',
        'api' => 'API',
        'account' => 'Accounts',
        );

    $user = wp_get_current_user();

    if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {

        $array = array_diff_key($array, $tabs_to_hide);

        foreach($tabs_to_hide as $tabs => $tab_title) {
            add_action( 'woocommerce_settings_' . $tabs , 'redirect_from_tab_page');
        }
    }

    return $array;
}

function redirect_from_tab_page() {
    $admin_url = get_admin_url();
    wp_redirect($admin_url);
    exit;
}

However, there are some important fields on some tabs that I want to keep for my multisite users to access and edit.

I hope what I tried to explain does make sense.

Any help is appreciated.

0
Najm Aldekhel 1 year 2021-12-23T19:43:12-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse