最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

woocommerce change order statuses count for specific role

programmeradmin2浏览0评论

I have two types of admin that can view the orders list. one of the admins just can view some of the orders.

I use below code to manipulate orders query for that admin:

add_action('pre_get_posts', function ($query) {
    global $pagenow;
    if (isset($query->query_vars['post_type'])) {
        if ($query->query_vars['post_type'] == 'shop_order' && ('edit.php' == $pagenow)) {

            if (!$query->is_main_query()) {
                return;
            }
            // I manipulate $query here
        }
    }
}, 1000, 1);

this code shows the orders that I want to show to that admin but this doesn't affect the order statuses on top of the table. I mean these numbers:

how can I fix these numbers to show correct order statuses to that admin?

I have two types of admin that can view the orders list. one of the admins just can view some of the orders.

I use below code to manipulate orders query for that admin:

add_action('pre_get_posts', function ($query) {
    global $pagenow;
    if (isset($query->query_vars['post_type'])) {
        if ($query->query_vars['post_type'] == 'shop_order' && ('edit.php' == $pagenow)) {

            if (!$query->is_main_query()) {
                return;
            }
            // I manipulate $query here
        }
    }
}, 1000, 1);

this code shows the orders that I want to show to that admin but this doesn't affect the order statuses on top of the table. I mean these numbers:

how can I fix these numbers to show correct order statuses to that admin?

Share Improve this question asked Dec 12, 2019 at 7:48 Amir SasaniAmir Sasani 1255 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

Normally pre_get_post doesn't change wordpress views post count. You have to call another filter hook to change to count.

add_action('pre_get_posts', function ($query) {
global $pagenow;
if (isset($query->query_vars['post_type'])) {
    if ($query->query_vars['post_type'] == 'shop_order' && ('edit.php' == $pagenow)) {

        if (!$query->is_main_query()) {
            return;
        }
        // I manipulate $query here

        // Get Post Count Here For Each Status

        add_filter( 'views_edit-shop_order', function( $views ) {

            $views['all'] = sprintf("<a href='%s'>All (%d)", $url_to_redirect, $all_count );
            $views['wc-processing'] = sprintf("<a href='%s'>Processing (%d)", $url_to_redirect, $processing_count );
            $views['wc-completed'] = sprintf("<a href='%s'>Completed (%d)", $url_to_redirect, $completed_count );
            $views['wc-failed'] = sprintf("<a href='%s'>Failed (%d)", $url_to_redirect, $failed_count );

            return $views;

            // Sample array we get print_r( $views )
            Array
            (
                [all] => All (24)
                [wc-processing] => Processing (3)
                [wc-completed] => Completed (19)
                [wc-failed] => Failed (2)
            )
        });
    }
}
}, 1000, 1);
发布评论

评论列表(0)

  1. 暂无评论