Customizing My Account Orders list post per page in Woocommerce

浪尽此生 提交于 2019-12-05 00:39:12

问题


Woocommerce 2.6.x has a special page at the user account (My Account) area where it displays the user's previous Orders.

This page is now paginated and it displays as default 15 items/page.

Here the screenshot of the woocommerce storefront theme Orders area with 8 lines:

I Can't find the way to change this.

How can I show only 7 items instead of the default number?

Thanks.


回答1:


Using a custom hooked function in woocommerce_my_account_my_orders_query hook, you can alter the orders query customizing the post_per_page argument to 7, just as you want.

Here is that code:

add_filter( 'woocommerce_my_account_my_orders_query', 'custom_my_account_orders', 10, 1 );
function custom_my_account_orders( $args ) {

    $args['posts_per_page'] = 7;
    return $args;
}

For woocommerce 3+ use limit instead:

add_filter( 'woocommerce_my_account_my_orders_query', 'custom_my_account_orders', 10, 1 );
function custom_my_account_orders( $args ) {
    // Set the post per page
    $args['limit'] = 7;

    return $args;
}

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

Note: Normally the default value for storefront theme and other themes too when displaying the list of orders in my account pages is 10 (but not 15).



来源:https://stackoverflow.com/questions/41916732/customizing-my-account-orders-list-post-per-page-in-woocommerce

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