Last active 1715617292

Malin's Avatar Malin revised this gist 1715617292. Go to revision

1 file changed, 41 insertions

orders-in-admin-bar.php(file created)

@@ -0,0 +1,41 @@
1 + // for QRh
2 +
3 + function add_order_counts_to_admin_bar( $wp_admin_bar ) {
4 + if ( ! current_user_can( 'manage_woocommerce' ) ) {
5 + return;
6 + }
7 +
8 + // Query total orders
9 + $args_total = array(
10 + 'limit' => -1,
11 + 'return' => 'ids',
12 + 'status' => array('any')
13 + );
14 + $total_orders = wc_get_orders( $args_total );
15 + $total_count = count( $total_orders );
16 +
17 + // Query processing orders
18 + $args_processing = array(
19 + 'limit' => -1,
20 + 'return' => 'ids',
21 + 'status' => array('processing')
22 + );
23 + $processing_orders = wc_get_orders( $args_processing );
24 + $processing_count = count( $processing_orders );
25 +
26 + // Add total orders node
27 + $wp_admin_bar->add_node( array(
28 + 'id' => 'total_orders',
29 + 'title' => 'Total Orders: ' . $total_count,
30 + 'href' => admin_url('edit.php?post_type=shop_order'),
31 + ));
32 +
33 + // Add processing orders node
34 + $wp_admin_bar->add_node( array(
35 + 'id' => 'processing_orders',
36 + 'title' => 'Processing Orders: ' . $processing_count,
37 + 'href' => admin_url('edit.php?post_type=shop_order&post_status=wc-processing'),
38 + ));
39 + }
40 +
41 + add_action( 'admin_bar_menu', 'add_order_counts_to_admin_bar', 100 );
Newer Older