Commit 5f57267f9f8 for woocommerce
commit 5f57267f9f8bd40d2e12d84d2207c399910d8869
Author: Darren Ethier <darren@roughsmootheng.in>
Date: Wed Oct 14 16:20:24 2026 -0400
Fix WC_Data date check regression from #68676 (#69843)
Use instanceof for the WC_DateTime check in WC_Data::set_date_prop()
#68676 passed $allow_string = true to is_a() to avoid the PHP 8.6
deprecation for string arguments. That also made a class-name string
such as "WC_DateTime" pass the check, so set_date_prop() assigned the
string as the date and then called setTimezone() or set_utc_offset()
on it, an uncaught Error. It also broke PHPStan on trunk.
instanceof returns the same result as the original is_a() call for
every value and never triggers the deprecation. Remove the baseline
entry for the old is_a() call, which no longer exists.
diff --git a/plugins/woocommerce/changelog/fix-68676-wc-data-is-a-regression b/plugins/woocommerce/changelog/fix-68676-wc-data-is-a-regression
new file mode 100644
index 00000000000..b0c860fcae5
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-68676-wc-data-is-a-regression
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Fix an unreleased WC_Data date-handling regression from #68676 that broke PHPStan; no merchant-facing change.
+
diff --git a/plugins/woocommerce/includes/abstracts/abstract-wc-data.php b/plugins/woocommerce/includes/abstracts/abstract-wc-data.php
index b1a9ae54d77..bf8101cd03d 100644
--- a/plugins/woocommerce/includes/abstracts/abstract-wc-data.php
+++ b/plugins/woocommerce/includes/abstracts/abstract-wc-data.php
@@ -978,7 +978,7 @@ abstract class WC_Data {
return;
}
- if ( is_a( $value, 'WC_DateTime', true ) ) {
+ if ( $value instanceof WC_DateTime ) {
$datetime = $value;
} elseif ( is_numeric( $value ) ) {
// Timestamps are handled as UTC timestamps in all cases.
diff --git a/plugins/woocommerce/phpstan-baseline.neon b/plugins/woocommerce/phpstan-baseline.neon
index 69bf75dc2f0..4d1c34cf5fb 100644
--- a/plugins/woocommerce/phpstan-baseline.neon
+++ b/plugins/woocommerce/phpstan-baseline.neon
@@ -240,12 +240,6 @@ parameters:
count: 4
path: includes/abstracts/abstract-wc-data.php
- -
- message: '#^Parameter \#1 \$object_or_string of function is_a expects object, int\<min, \-1\>\|int\<1, max\>\|string given\.$#'
- identifier: argument.type
- count: 1
- path: includes/abstracts/abstract-wc-data.php
-
-
message: '#^Parameter \#1 \$offset of method WC_DateTime\:\:set_utc_offset\(\) expects int, float given\.$#'
identifier: argument.type
diff --git a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-data-test.php b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-data-test.php
index 1bf127d7ed1..79c207a6e3e 100644
--- a/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-data-test.php
+++ b/plugins/woocommerce/tests/php/includes/abstracts/class-wc-abstract-data-test.php
@@ -72,4 +72,28 @@ class WC_Data_Test extends WC_Unit_Test_Case {
$this->assertEquals( [], $meta_data );
$data_object->read_meta_data();
}
+
+ /**
+ * @testdox Should store a WC_DateTime object passed to a date setter as a date.
+ */
+ public function test_set_date_prop_accepts_wc_datetime_object(): void {
+ $order = new WC_Order();
+ $datetime = new WC_DateTime( '@1700000000', new DateTimeZone( 'UTC' ) );
+
+ $order->set_date_created( $datetime );
+
+ $this->assertInstanceOf( WC_DateTime::class, $order->get_date_created() );
+ $this->assertSame( 1700000000, $order->get_date_created()->getTimestamp() );
+ }
+
+ /**
+ * @testdox Should not treat the WC_DateTime class name passed to a date setter as a date object.
+ */
+ public function test_set_date_prop_does_not_treat_class_name_as_date_object(): void {
+ $order = new WC_Order();
+
+ $order->set_date_created( 'WC_DateTime' );
+
+ $this->assertNotSame( 'WC_DateTime', $order->get_date_created(), 'The class name string must not be stored as the date' );
+ }
}