2016-04-24 63 views

回答

1

這是不是很漂亮,但是,將工作:

add_filter('woocommerce_settings_tabs_array','remove_setting_tab', 50); 

function remove_setting_tab($settings_tabs) { 
    //Default Tabs are : 
    //array(8) { ["general"]=> string(7) "General" ["products"]=> string(8) "Products" ["tax"]=> string(3) "Tax" ["checkout"]=> string(8) "Checkout" ["shipping"]=> string(8) "Shipping" ["account"]=> string(8) "Accounts" ["email"]=> string(6) "Emails" ["api"]=> string(3) "API" }  
    $user = wp_get_current_user(); 
    if (isset($user->roles[0]) && $user->roles[0] == 'shop_manager') { 
     unset($settings_tabs['general']);// = array(); 
    } 

    return $settings_tabs; 
} 

add_filter('woocommerce_general_settings', 'setting_tab_empty_content'); 
function setting_tab_empty_content($settings){ 
    $user = wp_get_current_user(); 
    if (isset($user->roles[0]) && $user->roles[0] == 'shop_manager') { 
     if ($_SERVER['REQUEST_URI']=='/wp-admin/admin.php?page=wc-settings&tab=general') 
     { 
      die('<strong>No permissions</strong>'); 
     } 
    } 
} 
+1

@loicTheAztec,第一:由於模具();它不乾淨,並且由於$ _SERVER ['REQUEST_URI']檢查它可以防止WP函數的其餘部分運行,並且第二次檢查它:應該是更準確的檢查。但它是一個絕望的解決方案的解決方法。 –

+0

不知道爲什麼它不適合我。 unset部分工作正常,但die()導致此錯誤 警告:爲foreach()提供的無效參數在C:\ xampp \ htdocs \ 9ja \ wp-content \ plugins \ woocommerce \ includes \ admin \ class-wc 207行的-admin-settings.php –