简体   繁体   English

如何使用woocommerce从管理产品页面显示/隐藏某些类别?

[英]how can I show/hide some categories from the admin product page using woocommerce?

I've been trying to do this for a time, unfortunately I've found only solutions for the store(frontend) in cases the category is empty and so on. 我已经尝试过一段时间了,不幸的是,在类别为空等情况下,我只找到了store(frontend)的解决方案。

What I basically want to do, is when I create a new product, at the Prodct Categories section 我基本上想做的是在“产品类别”部分中创建新产品时 在此处输入图片说明

I want to show/hide some categories. 我想显示/隐藏一些类别。

So far I haven't found anything for this, any idea how can it be done? 到目前为止,我还没有发现任何东西,知道怎么做?

Thanks. 谢谢。

Try out below code : 试试下面的代码:

function is_edit_page($new_edit = null){
    global $pagenow;
    //make sure we are on the backend
    if (!is_admin()) return false;

    if($new_edit == "edit")
        return in_array( $pagenow, array( 'post.php',  ) );
    elseif($new_edit == "new") //check for new post page
        return in_array( $pagenow, array( 'post-new.php' ) );
    else //check for either new or edit
        return in_array( $pagenow, array( 'post.php', 'post-new.php' ) );
}


function so_28055266_filterGetTermArgs($args, $taxonomies) {
    global $typenow;

    if ($typenow == 'product') { 
        // check whether we're currently filtering selected taxonomy
        if (implode('', $taxonomies) == 'product_cat' && is_edit_page()) {
            //Add categories term ID that you want to show
            $cats = array(9,10,11,12); // List of category(term ID) that you want to add as an array

            if (empty($cats))
                $args['include'] = array(99999999); // no available categories
            else
                $args['include'] = $cats; //It will only show the category that you mentioned in above array
        }
    }

    return $args;
}

if (is_admin()) {
    add_filter('get_terms_args', 'so_28055266_filterGetTermArgs', 10, 2);
}

Let me know the output. 让我知道输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM