Commit 3dc82ab14b0 for woocommerce
commit 3dc82ab14b035c8605a8a0ecb4e0031f1cf72a06
Author: Mike Jolley <mike.jolley@me.com>
Date: Mon Oct 12 12:22:24 2026 +0100
Show order note times in the current store timezone (#69661)
* Fix order note times not following the store timezone
* Add changelog entry for order note timezone fix
diff --git a/plugins/woocommerce/changelog/48953-order-note-timezone b/plugins/woocommerce/changelog/48953-order-note-timezone
new file mode 100644
index 00000000000..b804154865c
--- /dev/null
+++ b/plugins/woocommerce/changelog/48953-order-note-timezone
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Show order note times in the current store timezone after the timezone setting changes.
diff --git a/plugins/woocommerce/includes/wc-order-functions.php b/plugins/woocommerce/includes/wc-order-functions.php
index 80b1d2052c7..ad787ec3d50 100644
--- a/plugins/woocommerce/includes/wc-order-functions.php
+++ b/plugins/woocommerce/includes/wc-order-functions.php
@@ -1192,7 +1192,8 @@ function wc_get_order_note( $data ) {
'woocommerce_get_order_note',
array(
'id' => (int) $data->comment_ID,
- 'date_created' => wc_string_to_datetime( $data->comment_date ),
+ // comment_date is frozen in the timezone the site had when the note was saved, so use the GMT date.
+ 'date_created' => wc_string_to_datetime( mysql_to_rfc3339( $data->comment_date_gmt ) . 'Z' ),
'content' => $data->comment_content,
'customer_note' => (bool) get_comment_meta( $data->comment_ID, 'is_customer_note', true ),
'added_by' => __( 'WooCommerce', 'woocommerce' ) === $data->comment_author ? 'system' : $data->comment_author,
diff --git a/plugins/woocommerce/tests/php/includes/wc-order-functions-test.php b/plugins/woocommerce/tests/php/includes/wc-order-functions-test.php
index 0e06b905eda..3a79a6cdc6b 100644
--- a/plugins/woocommerce/tests/php/includes/wc-order-functions-test.php
+++ b/plugins/woocommerce/tests/php/includes/wc-order-functions-test.php
@@ -606,4 +606,29 @@ class WC_Order_Functions_Test extends \WC_Unit_Test_Case {
'An unattributed refund should stay unattributed after a round trip through the data store.'
);
}
+
+ /**
+ * @testdox Should show an order note's time in the current site timezone after the timezone changes.
+ *
+ * @see https://github.com/woocommerce/woocommerce/issues/48953
+ */
+ public function test_wc_get_order_note_uses_current_site_timezone(): void {
+ update_option( 'timezone_string', 'America/New_York' );
+ $note_id = wp_insert_comment(
+ array(
+ 'comment_post_ID' => WC_Helper_Order::create_order()->get_id(),
+ 'comment_type' => 'order_note',
+ 'comment_content' => 'Order status changed from Pending payment to Completed.',
+ 'comment_approved' => 1,
+ 'comment_date' => '2024-06-28 11:34:05',
+ 'comment_date_gmt' => '2024-06-28 15:34:05',
+ )
+ );
+
+ update_option( 'timezone_string', 'Asia/Tokyo' );
+ $note = wc_get_order_note( $note_id );
+
+ $this->assertSame( strtotime( '2024-06-28 15:34:05 UTC' ), $note->date_created->getTimestamp(), 'The note should keep the moment it was created.' );
+ $this->assertSame( '2024-06-29 00:34:05', $note->date_created->date( 'Y-m-d H:i:s' ), 'The note should be shown in the new site timezone.' );
+ }
}