Processing Orders Count in the Admin Bar
Adds a toolbar item showing how many orders are waiting to be processed, linking to the filtered orders list. Visible to shop managers and administrators.
Opens WPIDE on
Code
add_action( 'admin_bar_menu', function ( $bar ) {
if ( ! current_user_can( 'edit_shop_orders' ) ) {
return;
}
$count = get_transient( 'wpide_processing_orders_count' );
if ( false === $count ) {
$result = wc_get_orders( array( 'status' => 'wc-processing', 'limit' => 1, 'paginate' => true, 'return' => 'ids', 'type' => 'shop_order' ) );
$count = (int) $result->total;
set_transient( 'wpide_processing_orders_count', $count, 5 * MINUTE_IN_SECONDS );
}
$hpos = class_exists( '\\Automattic\\WooCommerce\\Utilities\\OrderUtil' ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled();
$bar->add_node( array(
'id' => 'wpide-processing-orders',
'title' => sprintf( 'Orders to process: %d', (int) $count ),
'href' => admin_url( $hpos ? 'admin.php?page=wc-orders&status=wc-processing' : 'edit.php?post_type=shop_order&post_status=wc-processing' ),
) );
}, 80 );
add_action( 'woocommerce_order_status_changed', function () {
delete_transient( 'wpide_processing_orders_count' );
} );
Notes
The count is cached for five minutes to keep the toolbar fast.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.