Add Sort by Featured in WooCommerce

If you’re using WooCommerce to power your eCommerce store, you’ll love the newest addition to the plugin: sort by featured. This feature lets you quickly and easily sort your products by whether or not they are featured, making it simple to find what you’re looking for. Whether you’re hunting for a new featured product to promote or just want to tidy up your shop, this new feature is sure to come in handy!

By default, a customer can sort products by price, rating, date, and popularity. Adding Sort by Featured as a default sorting option will let your customers quickly see your featured products.

add_filter( 'woocommerce_get_catalog_ordering_args', 'custom_woocommerce_get_catalog_ordering_args' );
function custom_woocommerce_get_catalog_ordering_args( $args ) {
  $orderby_value = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
    if ( 'featured' == $orderby_value ) {
        $args['orderby'] = '_featured';
        $args['order'] = 'asc';
        $args['meta_key'] = '';
    }
    return $args;
}
add_filter( 'woocommerce_default_catalog_orderby_options', 'custom_woocommerce_catalog_orderby' );
add_filter( 'woocommerce_catalog_orderby', 'custom_woocommerce_catalog_orderby' );
function custom_woocommerce_catalog_orderby( $sortby ) {
    $sortbyfeatureed['featured'] = 'Featured';
    $sortby = $sortbyfeatureed + $sortby;
    return $sortby;
}

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close