我希望将woocommerce中的产品标签更改为分层显示。我试图寻找一个函数或钩子来改变这一点,但没有找到任何东西。
将感谢任何帮助或建议,以实现这一点。
谢谢。
发布于 2017-10-25 09:20:01
在woocommerce 3.0.4上测试
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 );发布于 2014-09-02 23:10:40
找到了解决方案,如果有人想做同样的事情,请看这里:
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);
发布于 2017-07-27 17:24:01
感谢上面的回答,为我节省了大量的研究,但您应该替换
$tax['labels']['parent_item'] = sprintf(__("Parent %s"),
$tax->labels->singular_name);
$tax['labels']['parent_item_colon'] = sprintf(__("Parent %s:"),
$tax->labels->singular_name);至
$tax['labels']->parent_item = sprintf(__("Parent %s"),
$tax['labels']->singular_name);
$tax['labels']->parent_item_colon = sprintf(__("Parent %s:"),
$tax['labels']->singular_name);https://stackoverflow.com/questions/25625229
复制相似问题