Hide “free” orders in WooCommerce orders section from admin panel

北城以北 提交于 2019-12-25 09:25:03

问题


I have some events that are zero cost (free). But they are getting my orders page really full and confusing.

Now in WooCommmerce orders admin panel, I want to hide all orders which have 0 as Price.

Is there any hook or filter function available to achieve this?


回答1:


You can remove Free order it by using parse_query filter with $pagenow global variable.

add_filter('parse_query', 'wh_alterAdminPostList');

function wh_alterAdminPostList($query)
{
    global $pagenow;
    if (is_admin() && $pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'shop_order')
    {
        $query->query_vars['meta_query'] = [
            [
                'key' => '_order_total',
                'value' => 0.00,
                'compare' => '>',
                'type' => 'DECIMAL',
            ]
        ];
    }
}

Code goes in function.php file of your active child theme (or theme). Or also in any plugin php files.
Code is tested and works.

Hope this helps!



来源:https://stackoverflow.com/questions/42567994/hide-free-orders-in-woocommerce-orders-section-from-admin-panel

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