Php Woocommerce-按管理中的特色产品筛选
从3.0版开始,Woocommerce删除了后端特色产品的排序选项。我在这里尝试了这个解决方案,但似乎不再有效 它创建了很好的下拉过滤器,但不幸的是没有过滤特色产品 因为我们有2000多种产品,所以一个接一个地寻找它们是非常整洁的。有没有办法对我们的特色产品进行分类或筛选Php Woocommerce-按管理中的特色产品筛选,php,woocommerce,Php,Woocommerce,从3.0版开始,Woocommerce删除了后端特色产品的排序选项。我在这里尝试了这个解决方案,但似乎不再有效 它创建了很好的下拉过滤器,但不幸的是没有过滤特色产品 因为我们有2000多种产品,所以一个接一个地寻找它们是非常整洁的。有没有办法对我们的特色产品进行分类或筛选 谢谢好的,这是代码,它似乎起作用了,作为奖励,你可以过滤掉库存产品和评级产品 add_action('restrict_manage_posts', 'featured_products_sorting'); function
谢谢好的,这是代码,它似乎起作用了,作为奖励,你可以过滤掉库存产品和评级产品
add_action('restrict_manage_posts', 'featured_products_sorting');
function featured_products_sorting() {
global $typenow;
$post_type = 'product'; // change to your post type
$taxonomy = 'product_visibility'; // change to your taxonomy
if ($typenow == $post_type) {
$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_filter('parse_query', 'featured_products_sorting_query');
function featured_products_sorting_query($query) {
global $pagenow;
$post_type = 'product'; // change to your post type
$taxonomy = 'product_visibility'; // change to your taxonomy
$q_vars = &$query->query_vars;
if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && 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;
}
}
好的,这是代码,它似乎在工作,作为奖励,你可以过滤掉库存产品和评级产品
add_action('restrict_manage_posts', 'featured_products_sorting');
function featured_products_sorting() {
global $typenow;
$post_type = 'product'; // change to your post type
$taxonomy = 'product_visibility'; // change to your taxonomy
if ($typenow == $post_type) {
$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_filter('parse_query', 'featured_products_sorting_query');
function featured_products_sorting_query($query) {
global $pagenow;
$post_type = 'product'; // change to your post type
$taxonomy = 'product_visibility'; // change to your taxonomy
$q_vars = &$query->query_vars;
if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && 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;
}
}