#69188·woocommerce

Shipping tests: which zone matches

Author: linear[bot]Created Sep 29, 2026Updated Sep 29, 2026
LabelsShippingplugin: woocommercefocus: unit testsRubikblock: cartblock: checkout

What this covers

The merchant draws regions by country, state and postcode, and the shopper's address should land in the intended one. Server-only; the blocks consume whichever zone wins.

Expected behaviour

  • Country, state and continent matching
  • An exact postcode, a wildcard, and a bare wildcard
  • Numeric ranges and ranges containing letters
  • A defined winner when two zones sit at the same position
  • The catch-all zone when nothing matches

Where it breaks

  • A range whose lower bound exceeds its upper bound
  • Postcodes typed with spaces or hyphens
  • A zone defined only by postcode turning out to be reachable from unexpected countries
  • A zone with no methods at all
  • A zone deleted while an order still references it

Already covered

legacy/unit-tests/shipping/shipping-zones.php::test_get_zone_matching_package holds four cases: a GB postcode-scoped zone, a GB continent zone, a US state zone and a US country zone. The same file covers get_zone, get_zone_by, get_shipping_method, enabled and ordered loading, and delete_zone.

Wildcard generation itself is pinned separately by test_wc_get_wildcard_postcodes in legacy/unit-tests/util/class-wc-tests-core-functions.php, including the bare *.

Not covered

  • Wildcards and the bare * reaching a zone through matching, as opposed to the generator in isolation
  • Numeric ranges, and ranges containing letters
  • A lower bound above its upper bound
  • The zone_order tie-break when two zones sit at the same position
  • Falling through to the catch-all zone when nothing matches
  • Postcodes typed with hyphens
  • A postcode-only zone turning out to be reachable from unexpected countries
  • A zone with no methods at all
  • A zone deleted while an order still references it

One row deliberately left out

A malformed ... postcode rule, one that does not split into exactly two parts, silently disables its zone for good. class-wc-shipping-zone-data-store.php:324 collects every zone holding any postcode row, wc_postcode_location_matcher() skips the malformed rule with continue (wc-core-functions.php:1626), :326 subtracts the zones that matched, and :329 excludes the remainder with NOT IN. A zone whose only postcode rule is malformed can therefore never match again, on any criterion.

A merchant would more likely expect the broken rule to be ignored and the zone to keep matching on its other criteria, so pinning today's behaviour would be wrong. Fixing it is a behaviour change, since zones that silently stopped matching would start matching again, and that needs a decision. Writing the rest of these tests does not, so leave this row out and file a report.

Conventions

Integration and unit tests only, no E2E.