Sale products but exclude products from category?

This topic has 3 replies, 2 voices, and was last updated 1 years, 10 months ago ago by Nancy

  • Avatar: Nancy
    Nancy
    Participant
    January 31, 2024 at 11:33

    Is it possible to have a page for products on sale, but exclude products from a certain category?
    and then have another page, with only the excluded sale products?

    I already did it through a custom query, but I would prefer it if it’s already built in. Are custom queries possible by the way?

    We have two pages > Sale (aanbiedingen) and an Outlet (koopjeshoek) page, We would prefer it if the Sale page doesn’t have products from the outlet, but both pages have products that have a sale price.

    I hope you can understand what I mean, is this possible, or should I stick to my custom query.

    My query goes even further and only let’s products with the word “THT” and “uitlopend” to be shown on the page but I understand that this is a bit too much to ask haha.

    2 Answers
    Avatar: Justin
    Luca Rossi
    Support staff
    February 1, 2024 at 07:51

    Hi @Nancy,

    There is a hook that you can achieve this change. Please add the following code under your functions.php file locates in your child theme:

    
    add_filter('woocommerce_products_widget_query_args', 'n2t_woocommerce_products_widget_query_args1');
    function n2t_woocommerce_products_widget_query_args1($args){
        if(is_page([123])){
    	    $args['tax_query'][] = array(
    		    'taxonomy' => 'product_cat',
    		    'field'    => 'id',
    		    'terms'    => [456],
                'operator' => 'NOT IN'
    	    );
        }
        return $args;
    }
    

    – The 123 number should be the SALE page ID.
    – The 456 number should be the category ID of koopjeshoek.

    Best Regards,
    8Theme’s Team

    Avatar: Nancy
    Nancy
    Participant
    February 1, 2024 at 13:34

    Thank you! I have another issue but opened a separate topic for it

  • Viewing 3 results - 1 through 3 (of 3 total)

The issue related to '‘Sale products but exclude products from category?’' has been successfully resolved, and the topic is now closed for further responses

We're using our own and third-party cookies to improve your experience and our website. Keep on browsing to accept our cookie policy.