Commit 0b2be6a7c13 for woocommerce
commit 0b2be6a7c13f1b84cdee7d57299cdfe93c603d35
Author: Oleksandr Aratovskyi <79862886+oaratovskyi@users.noreply.github.com>
Date: Tue Sep 15 15:05:18 2026 +0300
Fix fatal when structured data is requested without a type filter (#68732)
* Fix fatal when structured data is requested without a type filter
get_structured_data() treats a falsy $types as "return every node",
which is what the array_intersect_key() line further down does. The
new multi-type branch above it calls array_intersect( $types, ... )
unguarded, so passing null, false or an empty string throws a
TypeError as soon as any node uses an array @type.
Guard that call with is_array(), so a multi-type node behaves the same
as a scalar one for every $types value.
* Add changelog entry for the structured data type filter fix
diff --git a/plugins/woocommerce/changelog/fix-structured-data-falsy-types b/plugins/woocommerce/changelog/fix-structured-data-falsy-types
new file mode 100644
index 00000000000..7512fea8a6f
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-structured-data-falsy-types
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix a fatal error when structured data is requested without a type filter on a store whose markup uses multiple schema types.
diff --git a/plugins/woocommerce/includes/class-wc-structured-data.php b/plugins/woocommerce/includes/class-wc-structured-data.php
index aa70108c3a2..a064ddaf198 100644
--- a/plugins/woocommerce/includes/class-wc-structured-data.php
+++ b/plugins/woocommerce/includes/class-wc-structured-data.php
@@ -114,7 +114,7 @@ class WC_Structured_Data {
foreach ( $this->get_data() as $value ) {
if ( is_array( $value['@type'] ) ) {
$value_types = array_map( 'strtolower', $value['@type'] );
- $matching_types = array_intersect( $types, $value_types );
+ $matching_types = is_array( $types ) ? array_intersect( $types, $value_types ) : array();
$type = $matching_types ? reset( $matching_types ) : reset( $value_types );
$data[ $type ][] = $value;
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-structured-data-test.php b/plugins/woocommerce/tests/php/includes/class-wc-structured-data-test.php
index aced43c79b7..f228990762e 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-structured-data-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-structured-data-test.php
@@ -231,6 +231,35 @@ class WC_Structured_Data_Test extends \WC_Unit_Test_Case {
);
}
+ /**
+ * @testdox get_structured_data() returns every node when no types are requested.
+ *
+ * @testWith [null]
+ * [false]
+ * [""]
+ * [0]
+ *
+ * @param mixed $requested_types Falsy value standing in for "no type filtering".
+ */
+ public function test_get_structured_data_returns_array_type_when_no_types_requested( $requested_types ): void {
+ $this->structured_data->set_data(
+ array(
+ '@type' => array( 'Car', 'Product' ),
+ 'name' => 'Multi-type product',
+ )
+ );
+
+ $this->assertSame(
+ array(
+ '@context' => 'https://schema.org/',
+ '@type' => array( 'Car', 'Product' ),
+ 'name' => 'Multi-type product',
+ ),
+ $this->structured_data->get_structured_data( $requested_types ),
+ 'A falsy $types means "return everything", the same as it does for scalar @type nodes.'
+ );
+ }
+
/**
* @testdox Order structured data looks up the product image with an integer attachment ID.
*/