Hide On Sale products from Shop and Category Pages in WooCommerce [duplicate]

I found the following script to hide on sale products from the shop and category pages in Woocommerce:

function wc_exclude_sale_items_from_shop_page($query) {
    if ( is_admin() || ! $query->is_main_query() ) {
        return;
    }
    if ( is_shop() || is_product_category() ) {
        $query->set('meta_query', array(
            array(
                'key'     => '_sale_price',
                'compare' => 'NOT EXISTS',
            ),
        ));
    }
}

But it’s also hiding some products that do NOT have sale prices. Any ideas on why this might be happening?

Also — how would I adjust the script to also apply to the shop when the admin is logged in (so the admin sees the same thing as a customer) and product search pages?