Commit 9cf493dbb58 for woocommerce

commit 9cf493dbb5849a74ffadab6bd64df3a2a63f6574
Author: Luigi Teschio <gigitux@gmail.com>
Date:   Wed Jul 15 15:38:04 2026 +0200

    Fix widget block filtering in the Customizer (#66650)

    * Fix block filtering in the Customizer

    * Add changelog entry for Customizer block filtering

diff --git a/plugins/woocommerce/changelog/fix-customizer-widget-block-filtering b/plugins/woocommerce/changelog/fix-customizer-widget-block-filtering
new file mode 100644
index 00000000000..b0ff7437c06
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-customizer-widget-block-filtering
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Ensure unsupported WooCommerce blocks are hidden from the Customizer's widget inserter.
diff --git a/plugins/woocommerce/client/blocks/assets/js/filters/unregister-block-types/index.ts b/plugins/woocommerce/client/blocks/assets/js/filters/unregister-block-types/index.ts
index 29ea6d297c4..9c9c3e9f3af 100644
--- a/plugins/woocommerce/client/blocks/assets/js/filters/unregister-block-types/index.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/filters/unregister-block-types/index.ts
@@ -15,13 +15,21 @@ import {
 type BlockEditorContext = 'post' | 'widgets' | 'other';

 const getBlockEditorContext = (): BlockEditorContext => {
-	const adminPage = ( window as Window & { adminpage?: string } ).adminpage;
+	const wordpressWindow = window as Window & {
+		adminpage?: string;
+		pagenow?: string;
+	};
+	const adminPage = wordpressWindow.adminpage;

 	if ( [ 'post-php', 'post-new-php' ].includes( adminPage ?? '' ) ) {
 		return 'post';
 	}

-	if ( [ 'widgets-php', 'customize-php' ].includes( adminPage ?? '' ) ) {
+	// Customizer controls do not load the admin header, so adminpage is absent.
+	if (
+		[ 'widgets-php', 'customize-php' ].includes( adminPage ?? '' ) ||
+		wordpressWindow.pagenow === 'customize'
+	) {
 		return 'widgets';
 	}

diff --git a/plugins/woocommerce/client/blocks/assets/js/filters/unregister-block-types/test/index.ts b/plugins/woocommerce/client/blocks/assets/js/filters/unregister-block-types/test/index.ts
index cacce94f0c6..de291a7ceed 100644
--- a/plugins/woocommerce/client/blocks/assets/js/filters/unregister-block-types/test/index.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/filters/unregister-block-types/test/index.ts
@@ -13,8 +13,17 @@ jest.mock( '@wordpress/dom-ready', () => ( {
 	default: jest.fn( ( callback ) => callback() ),
 } ) );

-const loadFilter = ( adminPage: string | undefined, blockTypes: string[] ) => {
-	( window as Window & { adminpage?: string } ).adminpage = adminPage;
+const loadFilter = (
+	adminPage: string | undefined,
+	blockTypes: string[],
+	pageNow?: string
+) => {
+	const wordpressWindow = window as Window & {
+		adminpage?: string;
+		pagenow?: string;
+	};
+	wordpressWindow.adminpage = adminPage;
+	wordpressWindow.pagenow = pageNow;
 	( getBlockTypes as jest.Mock ).mockReturnValue(
 		blockTypes.map( ( name ) => ( { name } ) )
 	);
@@ -55,17 +64,24 @@ describe( 'unregister block types', () => {
 		}
 	);

-	it.each( [ 'widgets-php', 'customize-php' ] )(
+	it.each( [
+		[ 'widgets.php', 'widgets-php', undefined ],
+		[ 'the Customizer', undefined, 'customize' ],
+	] )(
 		'unregisters WooCommerce blocks outside the widget-editor allow list in %s',
-		( context ) => {
-			loadFilter( context, [
-				'woocommerce/product-search',
-				'woocommerce/product-filters',
-				'woocommerce/checkout',
-				'woocommerce/order-confirmation-status',
-				'woocommerce/new-widget-compatible-block',
-				'myplugin/client-only',
-			] );
+		( _context, adminPage, pageNow ) => {
+			loadFilter(
+				adminPage,
+				[
+					'woocommerce/product-search',
+					'woocommerce/product-filters',
+					'woocommerce/checkout',
+					'woocommerce/order-confirmation-status',
+					'woocommerce/new-widget-compatible-block',
+					'myplugin/client-only',
+				],
+				pageNow
+			);

 			expect( unregisterBlockType ).toHaveBeenCalledTimes( 3 );
 			expect( unregisterBlockType ).toHaveBeenCalledWith(