WooCommerce – filter by featured products in admin

You can sort your products list by the featured status. Just click on the star at the top of the column…. once will put all non-featured items at the top, and twice should reverse this and put all featured items at the top.

Your admin url will look like:

/wp-admin/edit.php?post_type=product&orderby=featured&order=desc

Sort products by featured status

EDIT:

Ok, so it turned out to not be that hard to filter by featured status. WooCommerce is filtering by “subtype”, and since that is also filtering by meta, we can mostly just copy their code and make a few adjustments.

The first function adds the select/drop-down element, while the second handles the adjustments to the admin query.

/**
 * 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, $wp_query;

    if ( $typenow == 'product' ) {

        // Subtypes
        if ( ! empty( $_GET['featured_status'] ) ) {
            if ( $_GET['featured_status'] == 'featured' ) {
                $query->query_vars['meta_value']    = 'yes';
                $query->query_vars['meta_key']      = '_featured';
            } elseif ( $_GET['featured_status'] == 'normal' ) {
                $query->query_vars['meta_value']    = 'no';
                $query->query_vars['meta_key']      = '_featured';
            }
        }

    }

}

add_filter( 'parse_query', 'wpa104537_featured_products_admin_filter_query' );

Updated for WooCommerce 3.0

The parse_query callback must be updated as the featured status is no longer stored as post meta.

/**
 * 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' );