Commit b4c10e0bc0d for woocommerce
commit b4c10e0bc0dc5750b4f3dc42358a7961680e147f
Author: Neil Carlo Sucuangco <necafasu@gmail.com>
Date: Tue Mar 24 16:35:37 2026 +0800
Fix featured products returning empty on multisite subsites (#63204)
* Fix featured products returning empty on multisite subsites
* fix test class docblock. drop bootstrap check
* Update wc-term-functions.php
* adjustments
---------
Co-authored-by: Vladimir Reznichenko <kalessil@gmail.com>
diff --git a/plugins/woocommerce/changelog/fix-63095-multisite-featured-products b/plugins/woocommerce/changelog/fix-63095-multisite-featured-products
new file mode 100644
index 00000000000..c75fafa596c
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-63095-multisite-featured-products
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fixed featured products not showing on multisite.
diff --git a/plugins/woocommerce/includes/wc-term-functions.php b/plugins/woocommerce/includes/wc-term-functions.php
index cf348d3e105..20e44c8ba43 100644
--- a/plugins/woocommerce/includes/wc-term-functions.php
+++ b/plugins/woocommerce/includes/wc-term-functions.php
@@ -667,14 +667,15 @@ function wc_get_product_visibility_term_ids() {
return array();
}
- static $term_ids = array();
+ static $term_ids_by_blog = array();
- // The static variable doesn't work well with unit tests.
- if ( count( $term_ids ) > 0 && ! class_exists( 'WC_Unit_Tests_Bootstrap' ) ) {
- return $term_ids;
+ $blog_id = get_current_blog_id();
+
+ if ( isset( $term_ids_by_blog[ $blog_id ] ) && ! class_exists( 'WC_Unit_Tests_Bootstrap' ) ) {
+ return $term_ids_by_blog[ $blog_id ];
}
- $term_ids = array_map(
+ $term_ids_by_blog[ $blog_id ] = array_map(
'absint',
wp_parse_args(
wp_list_pluck(
@@ -701,7 +702,7 @@ function wc_get_product_visibility_term_ids() {
)
);
- return $term_ids;
+ return $term_ids_by_blog[ $blog_id ];
}
/**
diff --git a/plugins/woocommerce/tests/php/includes/wc-term-functions-tests.php b/plugins/woocommerce/tests/php/includes/wc-term-functions-tests.php
index 7e6da817340..443bed7d650 100644
--- a/plugins/woocommerce/tests/php/includes/wc-term-functions-tests.php
+++ b/plugins/woocommerce/tests/php/includes/wc-term-functions-tests.php
@@ -4,7 +4,7 @@ declare( strict_types = 1 );
use Automattic\WooCommerce\Enums\ProductStockStatus;
/**
- * Class WC_Stock_Functions_Tests.
+ * Class WC_Term_Functions_Tests.
*/
class WC_Term_Functions_Tests extends \WC_Unit_Test_Case {
/**
@@ -176,4 +176,47 @@ class WC_Term_Functions_Tests extends \WC_Unit_Test_Case {
remove_action( 'edited_term_taxonomy', $action_callback );
}
+
+ /**
+ * @testdox Featured term ID matches current site.
+ */
+ public function test_get_product_visibility_term_ids_includes_featured(): void {
+ $term_ids = wc_get_product_visibility_term_ids();
+
+ $this->assertIsArray( $term_ids );
+ $this->assertArrayHasKey( 'featured', $term_ids );
+
+ $featured_term = get_term_by( 'name', 'featured', 'product_visibility' );
+
+ $this->assertNotFalse( $featured_term );
+ $this->assertSame( (int) $featured_term->term_taxonomy_id, (int) $term_ids['featured'] );
+ }
+
+ /**
+ * @testdox Featured filter returns only featured products.
+ */
+ public function test_wc_get_products_featured_returns_featured_products(): void {
+ $featured_product = WC_Helper_Product::create_simple_product( true );
+ $featured_product->set_featured( true );
+ $featured_product->save();
+
+ $regular_product = WC_Helper_Product::create_simple_product( true );
+ $regular_product->set_featured( false );
+ $regular_product->save();
+
+ $featured_products = wc_get_products(
+ array(
+ 'status' => 'publish',
+ 'limit' => 50,
+ 'featured' => true,
+ )
+ );
+
+ $featured_ids = array_map( fn( $product ) => $product->get_id(), $featured_products );
+
+ $this->assertSame( array( $featured_product->get_id() ), $featured_ids );
+
+ $featured_product->delete();
+ $regular_product->delete();
+ }
}