Commit 9aed18d780d for woocommerce
commit 9aed18d780d8e6a0c4a12dc7249bb2abc23fd0b0
Author: Peerapatfc <39871299+Peerapatfc@users.noreply.github.com>
Date: Mon Oct 26 21:07:52 2026 +0700
Fix order attribution inputs staying empty when tracking is enabled after page load (#70065)
* Fix order attribution inputs staying empty when tracking is enabled after page load
On the classic checkout, `setOrderTracking()` assigns `element.values` on the
`<wc-order-attribution-inputs>` elements. When this runs before the custom
element is defined, the elements are not upgraded yet, so the assignment
creates a plain own property named `values`. The constructor only looked for
an own `_values` property, so it never removed it, and it kept shadowing the
class's `values` setter. Later assignments, such as `setOrderTracking( true )`
after a consent banner is accepted, never reached the hidden inputs.
Check for the own `values` property in the constructor, restore the setter
and keep the values for `connectedCallback()` to stamp into the inputs.
Closes #70049
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
* Reword the pre-upgrade values comments in order attribution
Comment-only change suggested in review: say what the constructor
does with a `values` property set before the setter existed, and why
it deletes it.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* Rename the order attribution inputs test suite
The suite now also covers values assigned before the element is
upgraded, so name it after the inputs element instead of deduplication.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Raluca Stan <ralucastn@gmail.com>
diff --git a/plugins/woocommerce/changelog/70049-order-attribution-values-setter b/plugins/woocommerce/changelog/70049-order-attribution-values-setter
new file mode 100644
index 00000000000..9c8cdf64b34
--- /dev/null
+++ b/plugins/woocommerce/changelog/70049-order-attribution-values-setter
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix order attribution data missing from classic checkout orders when tracking is enabled after the page loads.
diff --git a/plugins/woocommerce/client/legacy/js/frontend/order-attribution.js b/plugins/woocommerce/client/legacy/js/frontend/order-attribution.js
index c3ac249b410..9a3535db5ae 100644
--- a/plugins/woocommerce/client/legacy/js/frontend/order-attribution.js
+++ b/plugins/woocommerce/client/legacy/js/frontend/order-attribution.js
@@ -181,12 +181,12 @@
super();
// Cache fieldNames available at the construction time, to avoid malformed behavior if they change in runtime.
this._fieldNames = Object.keys( wc_order_attribution.fields );
- // Allow values to be lazily set before CE upgrade.
- if ( this.hasOwnProperty( '_values' ) ) {
- let values = this.values;
- // Restore the setter.
+ // Copy any existing `values` into `_values`, they might have been set before the setter was defined.
+ if ( this.hasOwnProperty( 'values' ) ) {
+ const values = this.values;
+ // Delete `values` so later assignments use the setter.
delete this.values;
- this.values = values || {};
+ this._values = values || {};
}
}
/**
diff --git a/plugins/woocommerce/client/legacy/js/frontend/test/order-attribution.js b/plugins/woocommerce/client/legacy/js/frontend/test/order-attribution.js
index ce1fc1f09dc..84384f069c1 100644
--- a/plugins/woocommerce/client/legacy/js/frontend/test/order-attribution.js
+++ b/plugins/woocommerce/client/legacy/js/frontend/test/order-attribution.js
@@ -2,7 +2,7 @@
* @jest-environment jest-fixed-jsdom
*/
-describe( 'Order attribution input deduplication', () => {
+describe( 'Order attribution inputs', () => {
beforeAll( () => {
window.wc_order_attribution = {
fields: {
@@ -93,6 +93,28 @@ describe( 'Order attribution input deduplication', () => {
expect( document.getElementById( 'first' ) ).not.toBeNull();
expect( document.getElementById( 'second' ) ).toBeNull();
} );
+
+ test( 'keeps the setter working for values assigned before the element is upgraded', () => {
+ // Elements in a template are not upgraded, so assigning `values` creates a plain property.
+ const template = document.createElement( 'template' );
+ template.innerHTML =
+ '<wc-order-attribution-inputs></wc-order-attribution-inputs>';
+ const element = template.content.firstElementChild;
+ element.values = { source_type: 'first' };
+
+ // Inserting the element upgrades it and calls `connectedCallback()`.
+ document.body.appendChild( element );
+
+ const getInput = () =>
+ element.querySelector(
+ 'input[name="wc_order_attribution_source_type"]'
+ );
+ expect( getInput().value ).toBe( 'first' );
+
+ // A later assignment, such as the one from `setOrderTracking( true )`, must reach the input.
+ element.values = { source_type: 'second' };
+ expect( getInput().value ).toBe( 'second' );
+ } );
} );
describe( 'Order attribution sourcebuster.js init', () => {