Today's Orders Dashboard Widget
Shows how many WooCommerce orders came in today and their total, with the latest orders listed below.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! function_exists( 'wc_get_orders' ) || ! current_user_can( 'edit_shop_orders' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_woo_today', 'Today\'s Orders', function () {
$start = wp_date( 'Y-m-d' ) . ' 00:00:00';
$orders = wc_get_orders( array(
'limit' => 50,
'status' => array( 'wc-processing', 'wc-completed', 'wc-on-hold' ),
'date_created' => '>=' . strtotime( get_gmt_from_date( $start ) ),
'orderby' => 'date',
'order' => 'DESC',
) );
$total = 0;
foreach ( $orders as $order ) {
$total += (float) $order->get_total();
}
printf( '<p style="font-size:16px"><strong>%1$d</strong> orders · <strong>%2$s</strong></p>', count( $orders ), wp_kses_post( wc_price( $total ) ) );
if ( ! $orders ) {
return;
}
echo '<ul>';
foreach ( array_slice( $orders, 0, 5 ) as $order ) {
printf(
'<li><a href="%1$s">#%2$s</a> %3$s · %4$s</li>',
esc_url( $order->get_edit_order_url() ),
esc_html( $order->get_order_number() ),
esc_html( $order->get_formatted_billing_full_name() ),
wp_kses_post( $order->get_formatted_order_total() )
);
}
echo '</ul>';
} );
} );
Notes
The total sums the shown statuses in the store currency and counts up to 50 orders.
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.