Having problem with default sorting of the products

This topic has 4 replies, 3 voices, and was last updated 2 years, 6 months ago ago by Olga Barlow

  • Avatar: Jordan
    Jordan
    Participant
    June 9, 2022 at 17:48

    Hello, I would like to know how to manage the option the default sorting of products in the shop section and the product listing section and in categories to show sales products before all other. At the moment i think that the products are randomly sorted. I would like when a client open some category to see first of all the products which are on sale.

    Thanks in advance.
    Best regards!

    3 Answers
    Avatar: Rose Tyler
    Rose Tyler
    Support staff
    June 10, 2022 at 08:02

    Hello,

    All the available settings for the products sorting you can find in Appearance > Customize > WooCommerce > Product Catalog > Default Product Sorting > choose Default sorting. After that change the order of the products according to your needs using the sorting option https://gyazo.com/447b64249daa28be2a2ecd019fba9d87

    Regards

    Avatar: Jordan
    Jordan
    Participant
    June 10, 2022 at 12:28

    Thank you for the answer!
    I had to add additional code to functions so woocommerce can show first the products on sale and after that to select the option from Appearance > Customize > WooCommerce > Product Catalog > Default Product Sorting > choose Sales. For other users that want to have this option this is the function:

    add_filter( 'woocommerce_get_catalog_ordering_args', 'wcs_get_catalog_ordering_args' );
    function wcs_get_catalog_ordering_args( $args ) {
        $orderby_value = isset( $_GET['orderby'] ) ? woocommerce_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) );
         
        if ( 'on_sale' == $orderby_value ) {
            $args['orderby'] = 'meta_value_num';
            $args['order'] = 'DESC';
            $args['meta_key'] = '_sale_price'; 
        }
        return $args;
    }
     
    add_filter( 'woocommerce_default_catalog_orderby_options', 'wcs_catalog_orderby' );
    add_filter( 'woocommerce_catalog_orderby', 'wcs_catalog_orderby' );
    function wcs_catalog_orderby( $sortby ) {
        $sortby['on_sale'] = 'Sales';
        return $sortby;
    }
    Avatar: Olga Barlow
    Olga Barlow
    Support staff
    June 10, 2022 at 13:11

    Hello,

    Thank you very much that you shared your solution.

    Regards

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

The issue related to '‘Having problem with default sorting of the products’' 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.