Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to hide the Processing orders count from WooCommerce Orders menu

If you have a running WooCommerce store or even a test store, you would have noticed that there is a number displayed to the right of the Orders text in WooCommerce menu.

Hide the Processing orders count from WooCommerce Orders menu - WooCommerce Orders Menu Count

That’s the number of processing orders in your store.

WooCommerce provides a filter to hide this count: woocommerce_include_processing_order_count_in_menu

We can attach a function to this filter & return false. This filter is part of a larger ‘if’ condition that checks if the user has the permission / capability to view the count. All conditions of the ‘if’ below must be fulfilled for the count of processing orders to be shown.


if ( apply_filters( 'woocommerce_include_processing_order_count_in_menu', true ) && current_user_can( 'manage_woocommerce' ) && ( $order_count = wc_processing_order_count() ) ) {

We have written a function exclude_processing_order_count() that will return false. The current value is passed as $show to the function.

You can write the above code in the functions.php file of a child theme or create a quick plugin for this. The menu would no longer show the count of processing orders.
Hide the Processing orders count from WooCommerce Orders menu - WooCommerce Orders Menu Without Count

The count in the menu is displayed from the menu_order_count() in the includes/admin/class-wc-admin-menus.php file. This does not affect the count of orders that is shown on the Orders page. That will continue to show the correct number of orders by status.

Hide the Processing orders count from WooCommerce Orders menu - Orders Page Count

Understanding the wc_orders_count()

WooCommerce uses the wc_orders_count() to determine the number of orders for any status. The order status is passed as an argument to this function. You can find this function in the includes/wc-order-functions.php file.

The function first checks if the count of the desired order status is available in the object cache. If yes, it returns that count & skips the actual fetching of the order count. This is done using the wp_get_cache() function of WordPress.

If the count is not present in the order cache, it proceeds to fetching the count for that order status. Once the count if fetched, it is cached using the wp_cache_set() function. So whenever the order count needs to be displayed the next time, then it is loaded from the object cache.

WordPress Codex has a good tutorial on Object Caching & using WordPress cache functions.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x