Managing a WooCommerce store means keeping a close eye on your product pricing, especially when running promotions or sales. However, sorting through hundreds or even thousands of products to find those with active sale prices can be a tedious task using the default WordPress admin interface.
Imagine being able to quickly filter your product list to display only items that are currently on sale, allowing you to streamline your updates and promotional strategies…
In this post, I’ll show you how to enhance your WooCommerce admin panel with a simple PHP snippet that adds a custom filter for sale status.
This solution not only saves you time but also simplifies inventory management, making it easier to plan marketing campaigns and update product details efficiently. Let’s dive into the code and get started!

PHP Snippet: Add a “Filter by sale status” Dropdown @ WooCommerce Products Admin
/**
* @snippet Filter products by sale status @ WP admin
* @how-to businessbloomer.com/woocommerce-customization
* @author Rodolfo Melogli, Business Bloomer
* @compatible WooCommerce 9
* @community https://businessbloomer.com/club/
*/
add_action( 'restrict_manage_posts', 'bbloomer_filter_products_by_sale_status', 9999 );
function bbloomer_filter_products_by_sale_status() {
global $typenow;
if ( 'product' === $typenow ) {
$selected = isset( $_GET['sale_status'] ) ? $_GET['sale_status'] : '';
?>
<select name="sale_status">
<option value="">Filter by sale status</option>
<option value="on_sale" <?php selected( $selected, 'on_sale' ); ?>>On Sale</option>
<option value="not_on_sale" <?php selected( $selected, 'not_on_sale' ); ?>>Not on Sale</option>
</select>
<?php
}
}
add_filter( 'request', 'bbloomer_filter_products_query_by_sale_status' );
function bbloomer_filter_products_query_by_sale_status( $query_vars ) {
if ( isset( $query_vars['post_type'] ) && 'product' === $query_vars['post_type'] && isset( $_GET['sale_status'] ) && '' !== $_GET['sale_status'] ) {
$sale_status = sanitize_text_field( wp_unslash( $_GET['sale_status'] ) );
$now = current_time( 'timestamp' );
if ( ! isset( $query_vars['meta_query'] ) || ! is_array( $query_vars['meta_query'] ) ) {
$query_vars['meta_query'] = array();
}
if ( 'on_sale' === $sale_status ) {
$query_vars['meta_query'][] = array(
'key' => '_sale_price',
'value' => 0,
'compare' => '>',
'type' => 'NUMERIC',
);
$query_vars['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => '_sale_price_dates_from',
'compare' => 'NOT EXISTS',
),
array(
'key' => '_sale_price_dates_from',
'value' => $now,
'compare' => '<=',
'type' => 'NUMERIC',
),
);
$query_vars['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => '_sale_price_dates_to',
'compare' => 'NOT EXISTS',
),
array(
'key' => '_sale_price_dates_to',
'value' => $now,
'compare' => '>=',
'type' => 'NUMERIC',
),
);
} elseif ( 'not_on_sale' === $sale_status ) {
$query_vars['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => '_sale_price',
'compare' => 'NOT EXISTS',
),
array(
'key' => '_sale_price',
'value' => '',
'compare' => '=',
),
array(
'key' => '_sale_price_dates_from',
'value' => $now,
'compare' => '>',
'type' => 'NUMERIC',
),
array(
'key' => '_sale_price_dates_to',
'value' => $now,
'compare' => '<',
'type' => 'NUMERIC',
),
);
}
}
return $query_vars;
}
To correct my last post.
This script functions correctly if the product sale prices are $1.00 dollar or more.
Works great for what I need 🙂
Thank you
Cool!
This code doesn’t work. When I try to filter by Not on sale products it shows me 0 products
I was having some issues with it as well, so I spent some time revising it. Can you test again now please?