Woocommerce

New orders admin dashboard widget Woocommerce (custom)

    
//dashboard widget add_action('wp_dashboard_setup', 'order_dashboard_widget'); function order_dashboard_widget() { wp_add_dashboard_widget( 'order_dashboard_widget', // Widget slug. 'New/Processing Orders', // Title. 'order_dashboard_widget_display' // Display function. ); } function order_dashboard_widget_display() { // Add a 'View All' button $all_orders_url = admin_url('edit.php?post_type=shop_order'); echo '<a href="' . esc_url($all_orders_url) . '" class="button button-primary">View All</a>'; // Get the latest 5 processing orders $args = array( 'status' => 'processing', 'limit' => 5, 'orderby' => 'date', 'order' => 'DESC' ); $orders = wc_get_orders($args); // Check if there are orders if (!empty($orders)) { echo '<ul>'; foreach ($orders as $order) { $date_created = human_time_diff(strtotime($order->get_date_created()->date('Y-m-d H:i:s'))) . ' ago'; $order_url = admin_url('post.php?post=' . absint($order->get_id()) . '&action=edit'); echo '<li>'; echo '<a href="' . esc_url($order_url) . '">'; // Make the order clickable echo '#' . $order->get_order_number() . ' by ' . $order->get_formatted_billing_full_name(); echo ' - ' . $date_created; echo ' - €' . $order->get_total(); echo '</a>'; echo '</li>'; } echo '</ul>'; } else { echo 'No new orders.'; } }

Leave a Reply