Do you need to add an option to the default WooCommerce product sort filter to allow the ordering of sales items first? Luckily, this is easily done with a very simple function. You will need some basic knowledge of PHP and how to use functions correctly within a child theme or with a plugin such as Code Snippets.
Sorting Sales Items in WooCommerce
As you can see in the screenshot below the function will add an extra option to the WooCommerce ‘Sort by’ filter, this is dependant on the fact that you have a sorting filter as some themes may have removed this in place of a sidebar filter for example. If you still have the standard WooCommerce sorting filter then we can simply begin by using the function below to add the option to sort sales items above the regular priced stock.
Function to add sorting of sales items
You can use the function below without any changes to achieve what we want in this guide but if you want to change text of the filter option you can do.
/** * WooCommerce Sales Sorting Filter * https://lakewood.media/woocommerce-add-sales-filter/ */ add_filter( 'woocommerce_get_catalog_ordering_args', 'wcs_get_catalog_ordering_args' ); function wcs_get_catalog_ordering_args( $args ) { $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); if ( 'on_sale' == $orderby_value ) { $args['orderby'] = 'meta_value_num'; $args['order'] = 'DESC'; $args['meta_key'] = '_sale_price'; } return $args; } add_filter( 'woocommerce_default_catalog_orderby_options', 'wcs_catalog_orderby' ); add_filter( 'woocommerce_catalog_orderby', 'wcs_catalog_orderby' ); function wcs_catalog_orderby( $sortby ) { $sortby['on_sale'] = 'Sort by on sale'; return $sortby; }
How to use the filter as a link to your sales items?
This is pretty simple, you could place a menu link to your sales items pretty easily by simply adding the URL string to the end of your shop slug such as https://yourshop.com/products/?orderby=on_sale.
For more help with WooCommerce development visit our WordPress development services page.

Adam
Editor of the Lakewood Journal and founder of Lakewood media. Also an avid landscape and travel photographer.
You may also like
How to Attract the Right Audience with SEO Content
In this guide, we share tips on finding content ideas and how to make the most of your online presence so that the right people can find you organically.
0 Comments16 Minutes
The easy way to find SEO Competitors with Free Tools
While doing competitor analysis for keyword research, you will need to find relevant competitors, learn how to find SEO competitors with free SEO tools.
0 Comments9 Minutes
How to create a Link between Google Analytics and Search Console
Learn how to integrate Google Analytics with Search Console and obtain search data right in the Analytics' dashboard of your site.
0 Comments9 Minutes
How to do Keyword Research with free SEO tools
Learn how to perform keyword research with free SEO tools, learn how to obtain data with free tools, chrome extensions, and Google auto-complete feature.
0 Comments13 Minutes
Hi! Adam
Variable products do not work What to do?
Adam? Variable products do not work What to do?