wordpress - hide a woocommerce setting tab -


i hide specific woocommerce setting tab user role. not entire submenu, tab(checkout specific). want shop managers able access of settings, unable affect checkout settings.

how can achieve this?

if want remove tabs instead of hiding them using css, can add following yours theme functions.php:

add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 ); function remove_woocommerce_setting_tabs( $tabs ) {     // declare tabs want hide     $tabs_to_hide = array(         'tax',         'checkout',         'emails',         'api',         'accounts',         );       // current user     $user = wp_get_current_user();      // check if user shop-manager     if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {          // remove tabs want hide         $tabs = array_diff($tabs, $tabs_to_hide);     }      return $tabs; } 

this uses woocommerce 'woocommerce_settings_tabs_array' filter. more information on woocommerce filters , hooks can here: https://docs.woocommerce.com/wc-apidocs/hook-docs.html

this has added benefit no longer in html, if looks @ source, won't find elements.

you can still access urls. way of removing tabs instead of hiding them.

edit: i've figured out how stop access urls. copy following:

add_filter( 'woocommerce_settings_tabs_array', 'remove_woocommerce_setting_tabs', 200, 1 ); function remove_woocommerce_setting_tabs( $array ) {     // declare tabs want hide     $tabs_to_hide = array(         'tax' => 'tax',         'checkout' => 'checkout',         'email' => 'emails',         'api' => 'api',         'account' => 'accounts',         );      // current user     $user = wp_get_current_user();      // check if user shop_manager     if ( isset( $user->roles[0] ) && $user->roles[0] == 'shop_manager' ) {          // remove tabs want hide array         $array = array_diff_key($array, $tabs_to_hide);          // loop through tabs want remove , hook settings action         foreach($tabs_to_hide $tabs => $tab_title) {             add_action( 'woocommerce_settings_' . $tabs , 'redirect_from_tab_page');         }     }      return $array; }  function redirect_from_tab_page() {     // admin url , redirect     $admin_url = get_admin_url();     wp_redirect($admin_url);     exit; } 

this pretty same first bit of code, apart array structured differently , i've added foreach. foreach goes through list of tabs want block, hooks 'woocommerce_settings_{$tab}' action used show settings pages.

then created redirect_from_tab_page function redirect users default admin url. stops direct access different settings tabs.


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -