Commit 26fe166b718 for woocommerce

commit 26fe166b7189dd9908a6808fc4a2e3a70df65fd9
Author: Sulaiman Dauda <abiodauda@gmail.com>
Date:   Wed Dec 2 15:40:39 2026 +0000

    Give each webhook delivery a unique delivery ID (#69439)

diff --git a/plugins/woocommerce/changelog/fix-webhook-delivery-id-unique b/plugins/woocommerce/changelog/fix-webhook-delivery-id-unique
new file mode 100644
index 00000000000..f37bd43e2eb
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-webhook-delivery-id-unique
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Give each webhook delivery a unique delivery ID, even when several deliveries are sent in the same second.
diff --git a/plugins/woocommerce/includes/class-wc-webhook.php b/plugins/woocommerce/includes/class-wc-webhook.php
index 2b19fa197fa..c7c401d7140 100644
--- a/plugins/woocommerce/includes/class-wc-webhook.php
+++ b/plugins/woocommerce/includes/class-wc-webhook.php
@@ -579,15 +579,14 @@ class WC_Webhook extends WC_Legacy_Webhook {
 	}

 	/**
-	 * Generate a new unique hash as a delivery id based on current time and wehbook id.
-	 * Return the hash for inclusion in the webhook request.
+	 * Generate a new unique delivery ID for inclusion in the webhook request.
+	 * It is 32 random hex characters, so deliveries sent in the same second get different IDs.
 	 *
 	 * @since  2.2.0
 	 * @return string
 	 */
 	public function get_new_delivery_id() {
-		// Since we no longer use comments to store delivery logs, we generate a unique hash instead based on current time and webhook ID.
-		return wp_hash( $this->get_id() . strtotime( 'now' ) );
+		return wc_rand_hash( '', 32 );
 	}

 	/**
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-webhook-tests.php b/plugins/woocommerce/tests/php/includes/class-wc-webhook-tests.php
index d56da3088b3..2b8f03a650e 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-webhook-tests.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-webhook-tests.php
@@ -1431,4 +1431,39 @@ class WC_Webhook_Test extends WC_Unit_Test_Case {
 		$this->assertSame( array(), $other_deliveries, 'A webhook registered on another site must not deliver.' );
 		$this->assertTrue( is_user_member_of_blog( $user_id, $other_site_id ) );
 	}
+
+	/**
+	 * @testdox Each delivery gets its own delivery ID, even when deliveries are sent in the same second.
+	 */
+	public function test_each_delivery_gets_a_unique_delivery_id(): void {
+		$product = WC_Helper_Product::create_simple_product();
+		$webhook = $this->create_active_webhook( 'product.updated' );
+		$webhook->set_user_id( 1 );
+		$webhook->save();
+
+		add_filter(
+			'pre_http_request',
+			function () {
+				return $this->mock_http_response( 200 );
+			}
+		);
+
+		$delivery_ids = array();
+		add_action(
+			'woocommerce_webhook_delivery',
+			function ( $http_args ) use ( &$delivery_ids ) {
+				$delivery_ids[] = $http_args['headers']['X-WC-Webhook-Delivery-ID'];
+			}
+		);
+
+		$webhook->deliver( $product->get_id() );
+		$webhook->deliver( $product->get_id() );
+
+		$this->assertCount( 2, $delivery_ids, 'Both deliveries should have been sent.' );
+		$this->assertNotSame( $delivery_ids[0], $delivery_ids[1], 'Two deliveries must not share a delivery ID.' );
+		foreach ( $delivery_ids as $delivery_id ) {
+			$this->assertSame( 32, strlen( $delivery_id ), 'The delivery ID should be 32 characters long.' );
+			$this->assertSame( 32, strspn( $delivery_id, '0123456789abcdef' ), 'The delivery ID should contain only lowercase hex characters.' );
+		}
+	}
 }