Commit 26928ec5fef for woocommerce
commit 26928ec5fef75612eff71f33ade6018dd8c2484d
Author: Jorge A. Torres <jorge.torres@automattic.com>
Date: Sat Aug 1 14:13:26 2026 +0100
Fix order-review moderation guard missing legacy reviews of variable-product variations (#67071)
diff --git a/plugins/woocommerce/changelog/fix-legacy-review-rejected-check-variations b/plugins/woocommerce/changelog/fix-legacy-review-rejected-check-variations
new file mode 100644
index 00000000000..8f77a879982
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-legacy-review-rejected-check-variations
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix the order-review moderation guard missing legacy reviews of variable-product variations.
diff --git a/plugins/woocommerce/src/Internal/OrderReviews/SubmissionHandler.php b/plugins/woocommerce/src/Internal/OrderReviews/SubmissionHandler.php
index f5011520c32..1005882c205 100644
--- a/plugins/woocommerce/src/Internal/OrderReviews/SubmissionHandler.php
+++ b/plugins/woocommerce/src/Internal/OrderReviews/SubmissionHandler.php
@@ -330,24 +330,6 @@ class SubmissionHandler {
return false;
}
- // Pre-10.9.0 reviews have no VARIATION_META_KEY row; treat that as 0.
- $variation_clause = 0 === $variation_id
- ? array(
- 'relation' => 'OR',
- array(
- 'key' => ItemEligibility::VARIATION_META_KEY,
- 'value' => '0',
- ),
- array(
- 'key' => ItemEligibility::VARIATION_META_KEY,
- 'compare' => 'NOT EXISTS',
- ),
- )
- : array(
- 'key' => ItemEligibility::VARIATION_META_KEY,
- 'value' => (string) $variation_id,
- );
-
$comments = get_comments(
array(
'post_id' => $product_id,
@@ -361,7 +343,18 @@ class SubmissionHandler {
'key' => ItemEligibility::ORDER_META_KEY,
'value' => (string) $order->get_id(),
),
- $variation_clause,
+ array(
+ 'relation' => 'OR',
+ array(
+ 'key' => ItemEligibility::VARIATION_META_KEY,
+ 'value' => (string) $variation_id,
+ ),
+ array(
+ // Pre-10.9.0 reviews have no VARIATION_META_KEY row at all.
+ 'key' => ItemEligibility::VARIATION_META_KEY,
+ 'compare' => 'NOT EXISTS',
+ ),
+ ),
),
)
);
diff --git a/plugins/woocommerce/tests/php/src/Internal/OrderReviews/SubmissionHandlerTest.php b/plugins/woocommerce/tests/php/src/Internal/OrderReviews/SubmissionHandlerTest.php
index 5795305e7b4..6ba54618e10 100644
--- a/plugins/woocommerce/tests/php/src/Internal/OrderReviews/SubmissionHandlerTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/OrderReviews/SubmissionHandlerTest.php
@@ -498,15 +498,20 @@ class SubmissionHandlerTest extends WC_Unit_Test_Case {
}
/**
- * A spam verdict recorded against one variation's explicit meta value must not block a sibling variation.
+ * A spam verdict recorded against one variation's explicit meta value is scoped to that variation and
+ * doesn't block a sibling. A verdict on a review predating VARIATION_META_KEY (pre-10.9.0) has no
+ * per-variation identity to scope to, so it blocks the whole product on that order instead.
*
- * @testWith ["A", "error"]
- * ["B", "ok"]
+ * @testWith [true, "A", "error"]
+ * [true, "B", "ok"]
+ * [false, "A", "error"]
+ * [false, "B", "error"]
*
+ * @param bool $with_variation_meta False simulates a review written before 10.9.0, with no VARIATION_META_KEY row.
* @param string $resubmit Which variation, "A" or "B", resubmits a review.
* @param string $expected_status Expected row status for that resubmission.
*/
- public function test_resubmit_after_spam_verdict_is_scoped_to_its_variation( string $resubmit, string $expected_status ): void {
+ public function test_resubmit_after_spam_verdict_is_scoped_to_its_variation( bool $with_variation_meta, string $resubmit, string $expected_status ): void {
$variable = WC_Helper_Product::create_variation_product();
$variation_ids = $variable->get_children();
$variation_a = wc_get_product( $variation_ids[0] );
@@ -533,8 +538,11 @@ class SubmissionHandlerTest extends WC_Unit_Test_Case {
)
);
add_comment_meta( $comment_id, ItemEligibility::ORDER_META_KEY, (int) $order->get_id(), true );
- add_comment_meta( $comment_id, ItemEligibility::VARIATION_META_KEY, (int) $variation_a->get_id(), true );
+ if ( $with_variation_meta ) {
+ add_comment_meta( $comment_id, ItemEligibility::VARIATION_META_KEY, (int) $variation_a->get_id(), true );
+ }
wp_spam_comment( $comment_id );
+ ItemEligibility::reset_cache();
$target = 'A' === $resubmit ? $variation_a : $variation_b;
$item = 'A' === $resubmit ? $item_a : $item_b;