Commit 26cb7d12b06 for woocommerce

commit 26cb7d12b06e01b6d6f4295392e7d638a449d0a4
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date:   Tue Oct 27 09:29:23 2026 +0100

    [Fix] Harden parent terms traversing in ProductSchema::prime_product_hierarchical_taxonomies_cache (#70278)

diff --git a/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductSchema.php b/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductSchema.php
index a8ad46c38eb..c8ffbb09af6 100644
--- a/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductSchema.php
+++ b/plugins/woocommerce/src/StoreApi/Schemas/V1/ProductSchema.php
@@ -708,7 +708,7 @@ class ProductSchema extends AbstractSchema {
 				// Collect the chain of parent term IDs for cache priming below.
 				foreach ( $product_terms as $term ) {
 					$current = $term->term_id;
-					while ( isset( $parent_map[ $current ] ) ) {
+					while ( isset( $parent_map[ $current ] ) && ! in_array( $parent_map[ $current ], $term_hierarchy_ids, true ) ) {
 						$parent_id            = $parent_map[ $current ];
 						$term_hierarchy_ids[] = $parent_id;
 						$current              = $parent_id;