Commit 8115f3a85d4 for woocommerce

commit 8115f3a85d4ab6abf05863ea2b60cc7c7c912dd3
Author: Vlad Olaru <vlad.olaru@automattic.com>
Date:   Fri Jul 24 11:53:29 2026 +0300

    Add regression coverage for classic checkout shipping selection (#66923)

    * test: cover checkout hidden shipping fallback

    Context: Classic checkout already skips the shipping fieldset when ship_to_different_address is unchecked and the cart still needs a shipping address.

    Problem: The behavior behind #34986 had validation coverage but no direct guard proving hidden or autofilled shipping fields are discarded in favor of billing values.

    Solution: Add a focused checkout regression test that posts conflicting hidden shipping values, verifies billing-to-shipping normalization, and restores request/cart state after the assertion.

    Refs #34986

    * test(checkout): Distinguish shipping address selection

    Classic checkout already ignores hidden shipping fields when a shopper leaves the separate-address option unchecked.

    The initial regression test proved that fallback but would also pass if checkout always replaced explicit shipping data with billing. It also created a persisted product even though the shipping-address predicate was already controlled directly.

    Cover checked and unchecked selections with the same address fixture, preserve posted shipping for the checked case, and remove unrelated data and redundant setup while retaining complete request and filter cleanup.

    Refs #34986

    * chore: add checkout regression changelog

    Context: The #34986 branch adds focused classic checkout regression coverage.\n\nProblem: The affected WooCommerce package requires a changelog entry before publication.\n\nSolution: Record the test-only change as a patch-level development entry.\n\nRefs #34986

    * test: cover explicitly unchecked ship_to_different_address value

    The regression test only exercised the omitted field (false) and the
    checked '1' case. Neither distinguishes get_posted_data()'s `! empty()`
    guard from an `isset()` regression: an omitted field returns false under
    both, so the gap would go unnoticed. Posting the raw '0' value is the
    only input that separates the two — empty('0') is true in PHP, so the
    guard must still resolve to false.

    Parametrize the raw posted value (nullable to omit the field) alongside
    the expected outcome and add the ['0', false] case.

    Refs #34986

    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

    ---------

    Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

diff --git a/plugins/woocommerce/changelog/fix-34986-checkout-hidden-shipping-fields b/plugins/woocommerce/changelog/fix-34986-checkout-hidden-shipping-fields
new file mode 100644
index 00000000000..259445773ce
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-34986-checkout-hidden-shipping-fields
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Add regression coverage for classic checkout shipping address selection.
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php b/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php
index 6fcfae352c8..1b3c1833dfa 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-checkout-test.php
@@ -183,6 +183,67 @@ class WC_Checkout_Test extends \WC_Unit_Test_Case {
 		$this->assertEmpty( $errors->get_error_message( 'shipping_country_validation' ) );
 	}

+	/**
+	 * @testdox 'get_posted_data' respects the selected shipping address.
+	 *
+	 * @testWith [null, false]
+	 *           ["0", false]
+	 *           ["1", true]
+	 *
+	 * @param string|null $posted_value              Raw posted 'ship_to_different_address' value, or null to omit the field.
+	 * @param bool        $ship_to_different_address Whether a separate shipping address is expected to be selected.
+	 */
+	public function test_get_posted_data_respects_shipping_address_selection( $posted_value, $ship_to_different_address ) {
+		add_filter( 'woocommerce_cart_needs_shipping_address', '__return_true' );
+
+		$posted_data = array(
+			'woocommerce-process-checkout-nonce' => 'test-nonce',
+			'billing_first_name'                 => 'Billing',
+			'billing_last_name'                  => 'Customer',
+			'billing_company'                    => 'Billing Company',
+			'billing_address_1'                  => '123 Billing Street',
+			'billing_address_2'                  => 'Suite 4',
+			'billing_city'                       => 'Billington',
+			'billing_postcode'                   => '12345',
+			'billing_country'                    => 'US',
+			'billing_state'                      => 'CA',
+			'shipping_first_name'                => 'Hidden',
+			'shipping_last_name'                 => 'Autofill',
+			'shipping_company'                   => 'Hidden Company',
+			'shipping_address_1'                 => '999 Hidden Street',
+			'shipping_address_2'                 => 'Hidden Suite',
+			'shipping_city'                      => 'Hidden City',
+			'shipping_postcode'                  => '99999',
+			'shipping_country'                   => 'CA',
+			'shipping_state'                     => 'BC',
+		);
+		if ( null !== $posted_value ) {
+			$posted_data['ship_to_different_address'] = $posted_value;
+		}
+
+		$original_post = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Test cleanup restores the raw original request data.
+		$_POST         = $posted_data;
+
+		try {
+			$data = $this->sut->get_posted_data();
+		} finally {
+			$_POST = $original_post;
+			remove_filter( 'woocommerce_cart_needs_shipping_address', '__return_true' );
+		}
+
+		$this->assertSame( $ship_to_different_address, $data['ship_to_different_address'] );
+		$expected_address_type = $ship_to_different_address ? 'shipping' : 'billing';
+
+		foreach ( array( 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'postcode', 'country', 'state' ) as $field ) {
+			$this->assertArrayHasKey( 'shipping_' . $field, $data, "Shipping {$field} should be present after checkout normalization." );
+			$this->assertSame(
+				$posted_data[ $expected_address_type . '_' . $field ],
+				$data[ 'shipping_' . $field ],
+				"Shipping {$field} should use the {$expected_address_type} {$field} value."
+			);
+		}
+	}
+
 	/**
 	 * @testdox 'validate_checkout' adds a "We don't ship to country X" error but only if the country exists.
 	 *