Commit c94a9eac32b for woocommerce
commit c94a9eac32bde26bc56983550e233a9153433b81
Author: Lucio Giannotta <lucio.giannotta@a8c.com>
Date: Fri Dec 4 17:33:03 2026 -0500
Preserve geolocation values in storefront GET forms (#71528)
diff --git a/plugins/woocommerce/changelog/fix-geolocation-form-value b/plugins/woocommerce/changelog/fix-geolocation-form-value
new file mode 100644
index 00000000000..461ba7ec675
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-geolocation-form-value
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Preserve the full location value when shoppers submit storefront search and filter forms.
diff --git a/plugins/woocommerce/client/legacy/js/frontend/geolocation.js b/plugins/woocommerce/client/legacy/js/frontend/geolocation.js
index 4f239391548..0797dfbb478 100644
--- a/plugins/woocommerce/client/legacy/js/frontend/geolocation.js
+++ b/plugins/woocommerce/client/legacy/js/frontend/geolocation.js
@@ -107,7 +107,11 @@ jQuery( function( $ ) {
var hasField = $this.find( 'input[name="v"]' ).length > 0;
if ( method && 'get' === method.toLowerCase() && ! hasField ) {
- $this.append( '<input type="hidden" name="v" value="' + geo_hash + '" />' );
+ const input = document.createElement( 'input' );
+ input.type = 'hidden';
+ input.name = 'v';
+ input.value = geo_hash;
+ this.appendChild( input );
} else {
var href = $this.attr( 'action' );
if ( href ) {
diff --git a/plugins/woocommerce/client/legacy/js/frontend/test/geolocation.js b/plugins/woocommerce/client/legacy/js/frontend/test/geolocation.js
new file mode 100644
index 00000000000..b2415d951d8
--- /dev/null
+++ b/plugins/woocommerce/client/legacy/js/frontend/test/geolocation.js
@@ -0,0 +1,27 @@
+const $ = require( 'jquery' );
+
+describe( 'Geolocation on storefront forms', () => {
+ afterEach( () => {
+ document.body.replaceChildren();
+ window.history.replaceState( null, '', '/' );
+ delete window.wc_geolocation_params;
+ delete window.Cookies;
+ delete window.jQuery;
+ } );
+
+ it( 'submits the location hash exactly as supplied', async () => {
+ const hash = 'region&zone';
+ window.history.replaceState( null, '', '?' + new URLSearchParams( { v: hash } ) );
+ window.wc_geolocation_params = { home_url: window.location.origin, wc_ajax_url: '/' };
+ window.Cookies = { get: () => hash };
+ window.jQuery = $;
+ document.body.innerHTML = '<form method="get"></form>';
+
+ require( '../geolocation' );
+ await new Promise( ( resolve ) => $( () => resolve() ) );
+
+ const form = document.forms[ 0 ];
+ expect( form.elements.namedItem( 'v' ).type ).toBe( 'hidden' );
+ expect( $( form ).serializeArray() ).toEqual( [ { name: 'v', value: hash } ] );
+ } );
+} );