Displaying only sale products - by mkusinski

This topic has 4 replies, 2 voices, and was last updated 6 years, 8 months ago ago by Laranz

  • Avatar: mkusinski
    mkusinski
    Participant
    June 25, 2017 at 18:27

    Hi,

    How can make a shop page which displays only products that are on sale at the moment? I managed to do this by making a category named “SALE”. But it is time consuming to assign many products to a category and after end of sale to delete this assignment. Is it possible to make such page which automatically displays all products on sale?

    Thanks in advance
    Marcin

    3 Answers
    Avatar: laranz
    Laranz
    Participant
    June 26, 2017 at 05:41

    Hi Marcin,

    Can you try adding this in to your child theme’s functions.php?

    add_action( 'woocommerce_product_query', 'theme8_onsale_items' );
    function theme8_onsale_items( $q ){
    
        $product_ids_on_sale = wc_get_product_ids_on_sale();
        $q->set( 'post__in', $product_ids_on_sale );
    
    }

    Let us know,

    Thanks,
    laranz.

    Avatar: mkusinski
    mkusinski
    Participant
    July 4, 2017 at 22:50

    Hi, thank you for the answer. I added the code to functions.php in child theme but what should I do next. I can’t see any changes for now (no new widget for example). I would like to have – apart from existing pages – a standard shop page displaying only products on sale. Could you please give me step-by-step instructions.

    Thanks.

    Avatar: laranz
    Laranz
    Participant
    July 5, 2017 at 09:03

    Hi,

    I thought you want the shop page to include only the sale items, if that is not the case please remove the snippet in the functions.php file, You can do two ways,

    1. Use the “Products” widget from the Visual Composer element list,

    OR
    2. Use the default Woocommerce shortcode, https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-15

    Let us know,

    Thanks,
    laranz.

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

You must be logged in to reply to this topic.Log in/Sign up

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