Disable product data section for specific users only

[亡魂溺海] 提交于 2019-12-01 21:26:39

Supposing that your vendors have a custom user role, you can achieve this targeting this specific user role in your function, this way:

add_filter('woocommerce_product_data_tabs', 'verdors_remove_tab', 10, 1);
function verdors_remove_tab($tabs){

    // Set HERE your targeted user role SLUG
    $target_user_role = 'multivendor';

    // Get current user (object)
    $current_user = wp_get_current_user();
    $current_user_roles = $current_user->roles; // current user roles

    // Unsetting tabs for this specific user role
    if( in_array( $target_user_role, $current_user_roles ) ){
        unset($tabs['inventory']); // it is to remove inventory tab
        //unset($tabs['advanced']); // it is to remove advanced tab
        //unset($tabs['linked_product']); // it is to remove linked_product tab
        //unset($tabs['attribute']); // it is to remove attribute tab
        //unset($tabs['variations']); // it is to remove variations tab
    }
    return($tabs);
}

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

This code is tested and works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!