仅为特定用户禁用产品数据部分 [英] Disable product data section for specific users only

查看:82
本文介绍了仅为特定用户禁用产品数据部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 WooCommerce 后端,我知道您可以使用 functions.php 上的一些代码全局删除产品标签.

In WooCommerce backend, I know that you can remove the Product tabs globally with some code on functions.php.

但我只想为用户后端删除.我正在使用多供应商插件.

But I only want to remove for the user back end. I'm using a multivendor plugin.

我该怎么做?

我的代码:

function remove_tab($tabs){
    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);
}
add_filter('woocommerce_product_data_tabs', 'remove_tab', 10, 1);

谢谢.

推荐答案

假设你的供应商有一个自定义用户角色,你可以在你的函数中针对这个特定的用户角色来实现这个,这样:

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);
}

此代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中.

此代码已经过测试且有效.

This code is tested and works.

这篇关于仅为特定用户禁用产品数据部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆