在woocommerce管理产品列表中为产品标签添加过滤器下拉列表 [英] Add a filter dropdown for product tags in woocommerce admin product list
本文介绍了在woocommerce管理产品列表中为产品标签添加过滤器下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我还想在woocommerce产品页面的按类别过滤器旁边添加过滤器标签。下面的图片在下面,但是我想尽可能添加另一个下拉菜单。
I want to also add a filter tag next to the filter by category in the woocommerce products page. Below image is in ducth but I want to add another dropdown menu if possible.
推荐答案
尝试以下操作,将为管理产品列表中的产品标签添加过滤条件:
Try the following that will add filtering for product tags in admin product list:
add_action('restrict_manage_posts', 'product_tags_sorting');
function product_tags_sorting() {
global $typenow;
$taxonomy = 'product_tag';
if ( $typenow == 'product' ) {
$selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : '';
$info_taxonomy = get_taxonomy($taxonomy);
wp_dropdown_categories(array(
'show_option_all' => __("Show all {$info_taxonomy->label}"),
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'orderby' => 'name',
'selected' => $selected,
'show_count' => true,
'hide_empty' => true,
));
};
}
add_action('parse_query', 'product_tags_sorting_query');
function product_tags_sorting_query($query) {
global $pagenow;
$taxonomy = 'product_tag';
$q_vars = &$query->query_vars;
if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == 'product' && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) {
$term = get_term_by('id', $q_vars[$taxonomy], $taxonomy);
$q_vars[$taxonomy] = $term->slug;
}
}
代码会出现在您活跃孩子的functions.php文件中主题(或活动主题)。经过测试并有效。
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
这篇关于在woocommerce管理产品列表中为产品标签添加过滤器下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文