Home > Mobile >  Change default sorting in Woocommerce order list
Change default sorting in Woocommerce order list

Time:07-31

How can the default sorting of the Woocommerce order list be changed. For now each time I enter the order page, orders are displayed as DESC. I would like it to be ASC by default each time I enter the order page. Can anyone help?

CodePudding user response:

These code will do the work.

add_filter( 'woocommerce_order_query_args', function ( $args ) {
    $args['order'] = 'ASC';
    
    return $args;
} );

CodePudding user response:

As I found another custom order solution in the forum:

sort-orders-by-paid-date-in-woocommerce-admin-order-list

I edited the code mentioned in there to the following, which worked out:

    function action_parse_query( $query ) { 
    global $pagenow;

    // Initialize
    $query_vars = &$query->query_vars;
    
    // Only on WooCommerce admin order list
    if ( is_admin() && $query->is_main_query() && $pagenow == 'edit.php' && $query_vars['post_type'] == 'shop_order' ) {

        
        // Set
        $query->set( 'orderby', 'date' );
        $query->set( 'order', 'ASC' );
    }
}
add_action( 'parse_query', 'action_parse_query', 10, 1 );
  • Related