首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何让woocommerce的产品标签层次化?

如何让woocommerce的产品标签层次化?
EN

Stack Overflow用户
提问于 2014-09-02 21:57:40
回答 4查看 2K关注 0票数 3

我希望将woocommerce中的产品标签更改为分层显示。我试图寻找一个函数或钩子来改变这一点,但没有找到任何东西。

将感谢任何帮助或建议,以实现这一点。

谢谢。

EN

回答 4

Stack Overflow用户

发布于 2017-10-25 09:20:01

在woocommerce 3.0.4上测试

代码语言:javascript
复制
function my_woocommerce_taxonomy_args_product_tag( $array ) {
    $array['hierarchical'] = true;
    return $array;
};
add_filter( 'woocommerce_taxonomy_args_product_tag', 'my_woocommerce_taxonomy_args_product_tag', 10, 1 );
票数 5
EN

Stack Overflow用户

发布于 2014-09-02 23:10:40

找到了解决方案,如果有人想做同样的事情,请看这里:

代码语言:javascript
复制
function reregister_taxonomy_pro_tags() {
    # the post types that the taxonomy is registered to
    $post_types = array('product');
    # set this to the taxonomy name
    $tax_name = 'product_tag';
    # load the already created taxonomy as array so we can
    # pass it back in as $args to register_taxonomy
    $tax = (array)get_taxonomy($tax_name);

    if ($tax) {
        # adjust the hierarchical necessities
        $tax['hierarchical'] = true;
        $tax['rewrite']['hierarchical'] = true;

        # adjust the hierarchical niceties (these could be ignored)
        $tax['labels']['parent_item'] = sprintf(__("Parent %s"),
        $tax->labels->singular_name);
        $tax['labels']['parent_item_colon'] = sprintf(__("Parent %s:"),
        $tax->labels->singular_name);

        # cast caps to array as expected by register_taxonomy
        $tax['capabilities'] = (array)$tax['cap'];
        # cast labels to array
        $tax['labels'] = (array)$tax['labels'];
        # register the taxonomy with our new settings
        register_taxonomy($tax_name, array('product'), $tax);
    }
}

初始化具有延迟优先级的操作,以便加载其他分类

add_action('init','reregister_taxonomy_pro_tags',9999);

票数 2
EN

Stack Overflow用户

发布于 2017-07-27 17:24:01

感谢上面的回答,为我节省了大量的研究,但您应该替换

代码语言:javascript
复制
    $tax['labels']['parent_item'] = sprintf(__("Parent %s"),
    $tax->labels->singular_name);
    $tax['labels']['parent_item_colon'] = sprintf(__("Parent %s:"),
    $tax->labels->singular_name);

代码语言:javascript
复制
$tax['labels']->parent_item = sprintf(__("Parent %s"),
$tax['labels']->singular_name);
$tax['labels']->parent_item_colon = sprintf(__("Parent %s:"),
$tax['labels']->singular_name);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25625229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档