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
Multiple Location SEO for local businesses
Better understand how to optimise your local business for local SEO. Target new areas and perform better in local search.
0 Comments7 Minutes
Beginners SEO Guide: Local SEO in London
Competing within London is a difficult task when it comes to local SEO. Our beginners guide will help you get started with Local SEO.
0 Comments12 Minutes
How to add Google Analytics to your WordPress site with Google Tag Manager
Wondering how to get started with Google Tag Manager? This quick guide shows you how to make a Google Analytics tag and add it to WordPress.
0 Comments12 Minutes
Getting started with Gutenberg. A Beginners Guide.
This guide helps you adapt to the Gutenberg WordPress editor. Make the most of the new features and understand the basics of Gutenberg.
0 Comments27 Minutes
How to use Gutenberg for posts only & WP Bakery (Visual Composer) for pages
How to use Gutenberg for posts only while keeping your page builders for pages and custom post types.
0 Comments5 Minutes
Why are backlinks important for SEO?
Why are backlinks still important for SEO in 2018? We look at the reasons you should still focus on backlink building in your SEO campaigns today.
0 Comments8 Minutes