WooCommerce admin products filter by on sale

I needed the ability to filter the WooCommerce products list within admin by products which where on sale. This was to allow the client to easily find products they have put on offer within certain categories. The below code achieves this.

It does need some work, as it currently ignores the on sale start and end dates, however you should be able to easily modify it for this purpose.

 

This code is provided as it and may require changes to work for your needs.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

13 Comments

  1. Jarkko Saltiola

    Thank’s for this, helped a bit.

    There’s a little typo though. Line 32 gives “PHP Parse error: syntax error, unexpected ‘='”.

    So just change “= >” to “=>”.

  2. Great.

    It Worked, perfectly

    I was able to sort the products based on onsale products, giving me the opportunity to bulk edit only onsale products

    Thank you

  3. Hi,

    Thanks a lot !
    It works !
    You safe my time !
    Love you !

    • I need some help here.

      How to filter by Attribute?

      Would you help me, please..

      • I dont have any code examples to hand, but I do have another filter code example I have just posted. Maybe one of these may get you pointed in the right direction?

        I think you should be able to use the filter by image example, and change the attribute values / search paramamters. As the filter by image example is based around product attributes / meta data values.

        https://shanerutter.co.uk/woocommerce-admin-products-filter-by-image/

        Hope that helps get your in the right direction!

  4. Pingback: WooCommerce admin products filter by image | Shane Rutter Blog

  5. oppo

    1) fix
    $selected = filter_input(INPUT_GET, ‘product_sale’, FILTER_VALIDATE_INT);
    if ($selected == false) {
    $selected = 0;
    }
    $output .= ‘

    Filter by sale
    On sale
    Not on sale

    ‘;

    2) fix
    $selected = filter_input(INPUT_GET, ‘product_sale’, FILTER_VALIDATE_INT);
    if (!is_admin() || (isset($_GET[‘product’]) && $_GET[‘post_type’] != “product”) || !$selected ) {
    return $where;
    }

  6. Arek

    Thank’s!

    Fix for variations:

    change:
    1) SELECT p.ID to: SELECT p.ID, p.post_parent (2 places)
    2) return $n->ID; to return $n->post_parent > 0 ? $n->post_parent : $n->ID; (2 places)