简体   繁体   中英

Change default sorting in Woocommerce order list

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?

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 );

These code will do the work.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM