Pawan Kumawat

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.

 

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.

 

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

How To Add Menu In WordPress Admin Panel

How to add menu in WordPress admin panel – In this post we see how we can add custom menu to admin sidebar. Sometimes when we on WordPress and we need to show some features or any information in admin page then we can use this code snippet to create the same.

How to add custom order status in WooCommerce

To add a custom order status and customize its email template using `register_post_status`, `wc_order_statuses`, `woocommerce_email_actions`, and `woocommerce_email_classes`, you can follow these steps:

Add Custom Product Data Tab

Learn how to enhance your WooCommerce product editor by adding a custom product data tab. Follow a step-by-step guide using the woocommerce_product_data_tabs filter and the woocommerce_product_data_panels action. Create a custom tab with your desired label, and include your own fields or content within the panel. Customize your product data to collect and display additional information, providing a tailored experience for your WooCommerce products.