• Resolved anandmongol

    (@anandmongol)


    I am using the following code in my function.php. And it sorts and display only the single products, not sorting/listing the variable products which are on discount/sale.

    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'] = 'Хямдралын хувиар';
        return $sortby;
    }
    

    Therefore, anybody help me to — sort/display both simple & variable products which are on discount/sale. Currently it displays only the simple products which are on SALE.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to sorting and displaying products by sale/discount?’ is closed to new replies.