Commit e3a83d9049 for woocommerce
commit e3a83d904991b05582c8ab5c0d630bc3e1ecd6bb
Author: Luiz Reis <luiz.reis@automattic.com>
Date: Sun Jan 11 14:35:00 2026 -0300
Fraud Protection: Add WooCommerce version to event data (#62763)
diff --git a/plugins/woocommerce/src/Internal/FraudProtection/SessionDataCollector.php b/plugins/woocommerce/src/Internal/FraudProtection/SessionDataCollector.php
index 57cfde9088..4cd6aa22a8 100644
--- a/plugins/woocommerce/src/Internal/FraudProtection/SessionDataCollector.php
+++ b/plugins/woocommerce/src/Internal/FraudProtection/SessionDataCollector.php
@@ -65,6 +65,7 @@ class SessionDataCollector {
return array(
'event_type' => $event_type,
'timestamp' => gmdate( 'Y-m-d H:i:s' ),
+ 'wc_version' => WC()->version,
'session' => $this->get_session_data(),
'customer' => $this->get_customer_data(),
'order' => $this->get_order_data( $order_id_from_event ),
diff --git a/plugins/woocommerce/tests/php/src/Internal/FraudProtection/SessionDataCollectorTest.php b/plugins/woocommerce/tests/php/src/Internal/FraudProtection/SessionDataCollectorTest.php
index e05694e583..1150eb8a34 100644
--- a/plugins/woocommerce/tests/php/src/Internal/FraudProtection/SessionDataCollectorTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/FraudProtection/SessionDataCollectorTest.php
@@ -51,7 +51,7 @@ class SessionDataCollectorTest extends \WC_Unit_Test_Case {
}
/**
- * Test that collect() method returns properly structured nested array with 8 top-level keys.
+ * Test that collect() method returns properly structured nested array with 9 top-level keys.
*/
public function test_collect_returns_properly_structured_nested_array() {
$result = $this->sut->collect();
@@ -59,13 +59,14 @@ class SessionDataCollectorTest extends \WC_Unit_Test_Case {
$this->assertIsArray( $result );
$this->assertArrayHasKey( 'event_type', $result );
$this->assertArrayHasKey( 'timestamp', $result );
+ $this->assertArrayHasKey( 'wc_version', $result );
$this->assertArrayHasKey( 'session', $result );
$this->assertArrayHasKey( 'customer', $result );
$this->assertArrayHasKey( 'order', $result );
$this->assertArrayHasKey( 'shipping_address', $result );
$this->assertArrayHasKey( 'billing_address', $result );
$this->assertArrayHasKey( 'event_data', $result );
- $this->assertCount( 8, $result );
+ $this->assertCount( 9, $result );
}
/**
@@ -94,13 +95,22 @@ class SessionDataCollectorTest extends \WC_Unit_Test_Case {
$result = $this->sut->collect();
$this->assertIsArray( $result );
- $this->assertCount( 8, $result );
+ $this->assertCount( 9, $result );
// All sections should be initialized even if session unavailable.
$this->assertIsArray( $result['session'] );
$this->assertIsArray( $result['customer'] );
$this->assertIsArray( $result['order'] );
}
+ /**
+ * Test wc_version field is included in collected data.
+ */
+ public function test_wc_version_is_included() {
+ $result = $this->sut->collect();
+
+ $this->assertEquals( WC()->version, $result['wc_version'] );
+ }
+
/**
* Test timestamp format is UTC (gmdate format).
*/
@@ -742,7 +752,7 @@ class SessionDataCollectorTest extends \WC_Unit_Test_Case {
// Verify structure is intact even with minimal data.
$this->assertIsArray( $result );
- $this->assertCount( 8, $result );
+ $this->assertCount( 9, $result );
// All sections should be arrays.
$this->assertIsArray( $result['session'] );