Commit 5d86d8f40b6 for woocommerce

commit 5d86d8f40b68039d16419049a40a3abf065ca71c
Author: Sergey Mitroshin <sergeymitr@gmail.com>
Date:   Thu Nov 5 20:51:51 2026 -0500

    Guard the Allow header on UCP discovery 405 responses (#70733)

    Guard the Allow header on UCP discovery 405 responses.

diff --git a/plugins/woocommerce/changelog/fix-ucp-discovery-405-allow-header-guard b/plugins/woocommerce/changelog/fix-ucp-discovery-405-allow-header-guard
new file mode 100644
index 00000000000..3d2fc6b579b
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-ucp-discovery-405-allow-header-guard
@@ -0,0 +1,5 @@
+Significance: patch
+Type: dev
+Comment: Guard the Allow header on UCP discovery 405 responses with headers_sent(); unreleased code, no production change.
+
+
diff --git a/plugins/woocommerce/src/Internal/Ucp/UcpDiscovery.php b/plugins/woocommerce/src/Internal/Ucp/UcpDiscovery.php
index f100be59b78..4fd1498b2d6 100644
--- a/plugins/woocommerce/src/Internal/Ucp/UcpDiscovery.php
+++ b/plugins/woocommerce/src/Internal/Ucp/UcpDiscovery.php
@@ -90,7 +90,9 @@ final class UcpDiscovery implements RegisterHooksInterface {
 		// phpcs:ignore WordPress.Security.ValidatedSanitizedInput
 		if ( ! in_array( $_SERVER['REQUEST_METHOD'] ?? '', array( 'GET', 'HEAD' ), true ) ) {
 			// RFC 9110 requires a 405 to name the allowed methods.
-			header( 'Allow: GET, HEAD' );
+			if ( ! headers_sent() ) {
+				header( 'Allow: GET, HEAD' );
+			}
 			status_header( 405 );
 			exit;
 		}