add_action('woocommerce_admin_order_data_after_order_details', 'check_customer_orders_in_processing');
function check_customer_orders_in_processing($order) {
// Get the current order's customer ID
$customer_id = $order->get_customer_id();
$current_order_id = $order->get_id();
// Check if the order has a customer associated
if (!$customer_id) {
return; // Exit if there's no customer ID
}
// Set up query arguments to find orders for this customer in "processing" status
$args = [
'post_type' => 'shop_order',
'post_status' => 'wc-processing',
'numberposts' => -1,
'meta_query' => [
[
'key' => '_customer_user',
'value' => $customer_id,
'compare' => '=',
],
],
];
// Fetch orders that match the criteria
$orders = get_posts($args);
// Filter orders to exclude the current one
$other_processing_orders = array_filter($orders, function($other_order) use ($current_order_id) {
return $other_order->ID != $current_order_id;
});
// If there are other processing orders, display the notification
if (!empty($other_processing_orders)) {
echo '<div class="notice notice-warning">';
echo '<p><strong>This customer has other orders in processing status:</strong></p><p>';
$order_links = [];
foreach ($other_processing_orders as $other_order) {
$order_id = $other_order->ID;
$order_links[] = '<a href="' . esc_url(admin_url('post.php?post=' . $order_id . '&action=edit')) . '">#' . $order_id . '</a>';
}
// Join order links with a " - " separator
echo implode(' - ', $order_links);
echo '</p></div>';
}
}