Change sorting of WooCommerce My account customer orders

大憨熊 提交于 2020-06-08 19:42:31

问题


In WooCommerce, customers can log in to their account and see the order history. By default the orders are displaying with the newest order date first.

I want to turn this around, so the order with the oldest date shows first.

I can't find any place to change ordering from ASC/DESC, looking in the template file woocoommerce/myaccount/orders.php file.

<table class="woocommerce-orders-table woocommerce-MyAccount-orders shop_table shop_table_responsive my_account_orders account-orders-table">
    <thead>
        <tr>
            <?php foreach ( wc_get_account_orders_columns() as $column_id => $column_name ) : ?>
                <th class="woocommerce-orders-table__header woocommerce-orders-table__header-<?php echo esc_attr( $column_id ); ?>"><span class="nobr"><?php echo esc_html( $column_name ); ?></span></th>
            <?php endforeach; ?>
        </tr>
    </thead>

    <tbody>
        <?php foreach ( $customer_orders->orders as $customer_order ) :

Any way to alter the loop to display orders with the oldest date first?


回答1:


The filter hook woocommerce_my_account_my_orders_query allows to change the 'order' argument to ASC (ascending), changing the sorting behavior on My account customer orders list:

add_filter( 'woocommerce_my_account_my_orders_query', 'my_account_orders_query_change_sorting' );
function my_account_orders_query_change_sorting( $args ) {
    $args['order'] = 'ASC'; // Default is 'DESC'

    return $args;
}

Code goes in functions.php file of your active child theme (or active theme). Tested and work.



来源:https://stackoverflow.com/questions/56270594/change-sorting-of-woocommerce-my-account-customer-orders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!