Commit f5c1df995b1 for woocommerce

commit f5c1df995b132f40443c5891e267cf47437dd5bb
Author: Albert Juhé Lluveras <contact@albertjuhe.com>
Date:   Mon Sep 14 17:20:10 2026 +0200

    Prevent password-protected product reviews from showing up to wrong users when they were cached (#68426)

    * Prevent password-protected product reviews from showing up to wrong users when they were cached

    * Add changelog

    * Drop unnecessary md5()

diff --git a/plugins/woocommerce/changelog/fix-WOO6-159-shared-cached-product-reviews b/plugins/woocommerce/changelog/fix-WOO6-159-shared-cached-product-reviews
new file mode 100644
index 00000000000..0c934698879
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-WOO6-159-shared-cached-product-reviews
@@ -0,0 +1,5 @@
+Significance: patch
+Type: fix
+Comment: Prevent password-protected product reviews from showing up to wrong users when they were cached
+
+
diff --git a/plugins/woocommerce/src/StoreApi/Routes/V1/ProductReviews.php b/plugins/woocommerce/src/StoreApi/Routes/V1/ProductReviews.php
index 52fd6d6e8e5..a9e41495969 100644
--- a/plugins/woocommerce/src/StoreApi/Routes/V1/ProductReviews.php
+++ b/plugins/woocommerce/src/StoreApi/Routes/V1/ProductReviews.php
@@ -111,7 +111,11 @@ class ProductReviews extends AbstractRoute {
 			$prepared_args['offset'] = $prepared_args['number'] * ( absint( $request['page'] ) - 1 );
 		}

-		$unlocked_product_ids               = $this->get_unlocked_password_protected_product_ids( $prepared_args['post__in'] ?? array() );
+		$unlocked_product_ids = $this->get_unlocked_password_protected_product_ids( $prepared_args['post__in'] ?? array() );
+		sort( $unlocked_product_ids, SORT_NUMERIC );
+		// We need to set a cache domain to prevent the comment query from being cached across different sets of unlocked products.
+		$prepared_args['cache_domain'] = 'wc_store_api_product_reviews_' . implode( ',', $unlocked_product_ids );
+
 		$exclude_password_protected_reviews = function ( $clauses ) use ( $unlocked_product_ids ) {
 			return $this->exclude_password_protected_product_reviews( $clauses, $unlocked_product_ids );
 		};