In Woocommerce, We can filter the products by category, product type, stock status, quantity, etc. But we cannot filter the products by featured products by default. In this article, We will show you how to filter products by featured products in the Woocommerce backend.
We can easily add and remove any product to the featured products by clicking on the star icon. But when we have thousands of products and need to remove any product from the featured products list, It is not easy to find the products without any filter.
How to filter products by featured products in the Woocommerce backend
Add the below code in the theme function.php file.
/** * Filter products by type * * @access public * @return void */ function wpa104537_filter_products_by_featured_status() { global $typenow, $wp_query; if ($typenow=='product') : // Featured/ Not Featured $output .= "<select name='featured_status' id='dropdown_featured_status'>"; $output .= '<option value="">'.__( 'Show All Featured Statuses', 'woocommerce' ).'</option>'; $output .="<option value='featured' "; if ( isset( $_GET['featured_status'] ) ) $output .= selected('featured', $_GET['featured_status'], false); $output .=">".__( 'Featured', 'woocommerce' )."</option>"; $output .="<option value='normal' "; if ( isset( $_GET['featured_status'] ) ) $output .= selected('normal', $_GET['featured_status'], false); $output .=">".__( 'Not Featured', 'woocommerce' )."</option>"; $output .="</select>"; echo $output; endif; } add_action('restrict_manage_posts', 'wpa104537_filter_products_by_featured_status');
/** * Filter the products in admin based on options * * @access public * @param mixed $query * @return void */ function wpa104537_featured_products_admin_filter_query( $query ) { global $typenow; if ( $typenow == 'product' ) { // Subtypes if ( ! empty( $_GET['featured_status'] ) ) { if ( $_GET['featured_status'] == 'featured' ) { $query->query_vars['tax_query'][] = array( 'taxonomy' => 'product_visibility', 'field' => 'slug', 'terms' => 'featured', ); } elseif ( $_GET['featured_status'] == 'normal' ) { $query->query_vars['tax_query'][] = array( 'taxonomy' => 'product_visibility', 'field' => 'slug', 'terms' => 'featured', 'operator' => 'NOT IN', ); } } } } add_filter( 'parse_query', 'wpa104537_featured_products_admin_filter_query' );
After adding the both code, you will see new filter option in the backend:
Now you can see all featured products together.