Sorting by featured products on the shop page is a great way to highlight your top items and encourage customers to explore your best offerings. By sorting featured products at the top of the shop page, you can ensure that these products are seen first, increasing their visibility and driving more sales.
In this guide, we’ll show you how to adjust the WooCommerce shop page to sort by featured products first, without using a plugin.
Step 1: Modify the Shop Page Query to Sort by Featured Products
To sort by featured products on the shop page, we’ll use a custom function to adjust the product query so that featured products appear first in the default sorting order.
Code to Sort Featured Products First on the Shop Page
Add the following code to your theme’s functions.php file or a child theme:
/*
* Snippet: How to Sort by Featured Products on the Shop Page in WooCommerce – 2026
* Author: John Cook
* URL: https://wcsuccessacademy.com/?p=1695
* Tested with WooCommerce 10.7.0
* "This function modifies the shop page query to sort featured products first"
*/
function wcsuccess_sort_by_featured_products_first( $query ) {
if ( ! is_admin() && $query->is_main_query() && is_shop() ) {
$meta_query = $query->get( 'meta_query' );
// Add a meta query to check for featured products
$meta_query[] = array(
'relation' => 'OR',
array(
'key' => '_featured',
'value' => 'yes',
'compare' => '='
),
array(
'key' => '_featured',
'compare' => 'NOT EXISTS'
)
);
$query->set( 'meta_query', $meta_query );
// Order featured products first, followed by newest items
$query->set( 'orderby', array( 'meta_value' => 'DESC', 'date' => 'DESC' ) );
}
}
add_action( 'pre_get_posts', 'wcsuccess_sort_by_featured_products_first' );
Explanation:
- Condition Check: This function only runs on the shop page’s main query on the front end.
- Meta Query for Featured Products: Adds a meta query that filters products based on the
_featuredmeta key, ensuring that featured products are sorted first. - Sorting Logic: Sorts products to display featured items first, followed by non-featured products ordered by the latest date.
Step 2: Style Featured Products (Optional)
To make the featured products stand out even more on the shop page, consider applying a custom style. Here’s some optional CSS to highlight featured products.
CSS for Featured Products
Add this CSS to your theme’s style.css file or custom CSS area:
/* Style featured products */
.product.featured {
border: 2px solid #3498db; /* Blue border */
padding: 10px;
border-radius: 5px;
background-color: #f0f8ff;
}
Explanation:
- CSS Highlight: Adds a blue border and background to featured products, making them more noticeable on the shop page.
- Customisable Styling: Adjust colours, padding, and borders to fit your store’s branding.
Example Workflow
- Mark Products as Featured: In WooCommerce, set products as “Featured” in the product editor.
- Sorting Display: Featured products will now appear first on the shop page, followed by non-featured products sorted by date.
- Styling: Optionally, add custom styles to further distinguish featured products.
Conclusion
Sorting by featured products on the WooCommerce shop page is a simple and effective way to highlight your top items. By following this guide, you can ensure that featured products are seen first, helping to drive more customer engagement with your best products.
For more customisation options, explore our WooCommerce Visual Hooks Guide or our wp-config generator for advanced configurations.
I have been working with WordPress and WooCommerce since 2012 and have developed a deep knowledge of the content management system. Since 2012, I have developed several plugins and designed dozens of websites utilising different frameworks, CMS’s and programming languages. I am proficient in PHP, Python, Java, C, C++, R and JavaScript with limited experience in Go, Kotlin and Swift.
Educationally, I have a Master’s degree in cyber security a Bachelor’s (Hons, First Class) in Applied Research and a Graduate Certificate in Data Science. I’m currently undertaking PhD studies investigating IoT cybersecurity. I recently graduated with First Class Honours and Masters of Information Technology, receiving the Executive Dean’s Award for studies undertaken in the 2021 and 2022 academic years. I have worked in the information technology industry for the past 11 years primarily as a software/web developer specific to design, optimisation, network management and security. My research interests are in the areas of Internet of Things (IoT), 5G and Beyond Networks, information security for wireless networks and software development.
Stay In Touch

