Add Custom Taxonomy Filter on Products Dashboard.

How To Filter Products by Taxonomies in the Dashboard?

 

WooCommerce provide Many Product filters on admin screen , such as “Select a category”, “Filter by product type”, “Filter by stock status”.

For example ,if you want to add Custom filters like “Filter by tags” etc on products admin screen.
“Product tag” is a default taxonomies of WooCommerce same as “Product categories”. We can use ‘woocommerce_product_filters’ filter for adding other texonomy filters too.

 

Paste this code to your theme’s functions.php for adding filter to product admin screen.

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function CustomTaxonomyFilter( $data ) {
global $wp_query;
$data .= wc_product_dropdown_categories( array(
'show_option_none' => 'Filter by Tags',
'taxonomy' => 'product_tag',
'name' => 'product_tag',
'selected' => isset( $wp_query->query_vars['product_tag'] ) ? $wp_query->query_vars['product_tag'] : '',
) );
return $data;
}
add_filter('woocommerce_product_filters','CustomTaxonomyFilter' );
function CustomTaxonomyFilter( $data ) { global $wp_query; $data .= wc_product_dropdown_categories( array( 'show_option_none' => 'Filter by Tags', 'taxonomy' => 'product_tag', 'name' => 'product_tag', 'selected' => isset( $wp_query->query_vars['product_tag'] ) ? $wp_query->query_vars['product_tag'] : '', ) ); return $data; } add_filter('woocommerce_product_filters','CustomTaxonomyFilter' );
function CustomTaxonomyFilter( $data ) { 
  global $wp_query; 
  $data .= wc_product_dropdown_categories( array(
    'show_option_none' => 'Filter by Tags',
    'taxonomy' => 'product_tag',
    'name' => 'product_tag',
    'selected' => isset( $wp_query->query_vars['product_tag'] ) ? $wp_query->query_vars['product_tag'] : '',
  ) );
return $data;
}
add_filter('woocommerce_product_filters','CustomTaxonomyFilter' );

 

Same filter can be used for extra custum texomony added.

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function CustomTaxonomyFilter( $data ) {
global $wp_query;
$data .= wc_product_dropdown_categories( array(
'show_option_none' => 'Filter by Brands',
'taxonomy' => 'product_brand',
'name' => 'product_brand',
'selected' => isset( $wp_query->query_vars['product_brand'] ) ? $wp_query->query_vars['product_brand'] : '',
) );
return $data;
}
add_filter('woocommerce_product_filters','CustomTaxonomyFilter' );
function CustomTaxonomyFilter( $data ) { global $wp_query; $data .= wc_product_dropdown_categories( array( 'show_option_none' => 'Filter by Brands', 'taxonomy' => 'product_brand', 'name' => 'product_brand', 'selected' => isset( $wp_query->query_vars['product_brand'] ) ? $wp_query->query_vars['product_brand'] : '', ) ); return $data; } add_filter('woocommerce_product_filters','CustomTaxonomyFilter' );
function CustomTaxonomyFilter( $data ) { 
  global $wp_query; 
  $data .= wc_product_dropdown_categories( array(
    'show_option_none' => 'Filter by Brands',
    'taxonomy' => 'product_brand',
    'name' => 'product_brand',
    'selected' => isset( $wp_query->query_vars['product_brand'] ) ? $wp_query->query_vars['product_brand'] : '',
  ) );
return $data;
}
add_filter('woocommerce_product_filters','CustomTaxonomyFilter' );

 

Categories

Related Blogs

Ultimate Guide to Custom Meta Boxes in WordPress

In WordPress, `add_meta_boxes` is an action hook that allows developers to add custom meta boxes to different post types’ edit screens. Meta boxes are additional sections on the post editor screen where you can add and display custom fields or other types of data related to the post.

To list down future posts in WordPress

To list down future posts in WordPress, you can use the `WP_Query` class to customize the query and fetch future posts. The future posts are the ones with a post status of “future,” and their publication date is scheduled in the future.