/** * Auto-complete orders after Site B callback IF all items are virtual/downloadable. */ add_action('woocommerce_order_status_processing', function($order_id) { $order = wc_get_order($order_id); if (!$order) return; // Only if our callback note exists (so we don't affect other orders) $notes = wc_get_order_notes(['order_id' => $order_id, 'type' => 'internal']); $has_siteb_note = false; foreach ($notes as $n) { if (stripos($n->content, 'Payment confirmed via Site B callback') !== false) { $has_siteb_note = true; break; } } if (!$has_siteb_note) return; // Check: all items are virtual OR downloadable foreach ($order->get_items() as $item) { $product = $item->get_product(); if (!$product) continue; $is_ok = $product->is_virtual() || $product->is_downloadable(); if (!$is_ok) { return; // leave as processing if any physical product exists } } // Move to completed $order->update_status('completed', 'Auto-completed: digital order paid via Site B.'); }, 20);