Commit 5019a36b224 for woocommerce

commit 5019a36b2248cebbe3a166028aec9454273654d0
Author: Karol Manijak <20098064+kmanijak@users.noreply.github.com>
Date:   Mon Aug 17 14:00:36 2026 +0200

    Fix Product Gallery variation event ID normalization (#67728)

    * Fix variation event ID normalization

    * Add changelog entry for variation ID normalization

    * Allow zero featured image IDs

    * Relax variation event ID validation

    * Fix variation ID condition formatting

diff --git a/plugins/woocommerce/changelog/soften-product-gallery-variation-id-validation b/plugins/woocommerce/changelog/soften-product-gallery-variation-id-validation
new file mode 100644
index 00000000000..6fc0b01f90a
--- /dev/null
+++ b/plugins/woocommerce/changelog/soften-product-gallery-variation-id-validation
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Allow Product Gallery variation events to use numeric string IDs.
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/legacy-jquery-form.ts b/plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/legacy-jquery-form.ts
index c68e5f4b516..f6d66cf86fb 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/legacy-jquery-form.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/legacy-jquery-form.ts
@@ -26,9 +26,12 @@ import type {
 	LegacyVariationPayload,
 } from './types';

-/** A positive integer ID from the variation event payload. */
-const isValidId = ( id: unknown ): id is number =>
-	typeof id === 'number' && Number.isInteger( id ) && id > 0;
+/** Normalize an integer ID from the variation event payload. */
+const normalizeId = ( id: unknown ): number | undefined => {
+	const normalizedId = Number( id );
+
+	return Number.isInteger( normalizedId ) ? normalizedId : undefined;
+};

 /**
  * Subscribe to the legacy classic Add to Cart form's jQuery variation
@@ -48,14 +51,11 @@ export const subscribeLegacyJQueryFormVariations = (

 	const handleFound = withScope(
 		( _event?: unknown, variation?: LegacyVariationPayload ) => {
-			if (
-				isValidId( variation?.variation_id ) &&
-				isValidId( variation?.image_id )
-			) {
-				handlers.onVariationFound(
-					variation.variation_id,
-					variation.image_id
-				);
+			const variationId = normalizeId( variation?.variation_id );
+			const featuredImageId = normalizeId( variation?.image_id );
+
+			if ( variationId !== undefined && featuredImageId !== undefined ) {
+				handlers.onVariationFound( variationId, featuredImageId );
 				return;
 			}

diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/types.ts b/plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/types.ts
index f3888880fd2..eed6ceaa8c0 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/types.ts
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/product-gallery/types.ts
@@ -29,8 +29,8 @@ export type ProductGalleryConfig = WooCommerceConfig & {
 };

 export type LegacyVariationPayload = {
-	variation_id?: number;
-	image_id?: number;
+	variation_id?: number | string;
+	image_id?: number | string;
 };

 export type LegacyJQueryInstance = {