Shipping tests: when rates appear
What this covers
The merchant asks for shipping costs to stay hidden until an address is entered, and what an address-less shopper sees follows from that. PHP and client.
Expected behaviour
- With the setting off, everything is visible without an address
- With it on and no address, delivery rates are hidden while pickup stays
- Completing the address brings the rates back
- If any package cannot be collected, pickup disappears from the whole order
Where it breaks
- A partial address, country present and postcode missing
- A country whose locale does not require a postcode or a state at all
- Checkout fields removed by an extension
- An address entered and then cleared again
- The two messages, "enter an address" and "no options available", must not be confused
Already covered
class-wc-cart-default-shipping-method-test.php holds 5 tests over default selection, asserting concrete rate ids in store-api context: no auto-selection when only pickup is available and no address is entered, flat_rate:1 when both are available, flat_rate:1 when the setting is on and the address is complete, local_pickup:1 preserved when already chosen, and shortcode context always taking the first rate.
class-wc-cart-test.php::test_show_shipping_returns_true_with_local_pickup_enabled_and_no_address pins the pickup short-circuit in both shortcode and store-api contexts, and the locale tests around it cover address fields a country hides.
Not covered
remove_shipping_if_no_address() is the method that actually strips the rates, and no test reaches its stripping branch. It is hooked on woocommerce_shipping_packages at priority 11, so it runs after rates are calculated on every store-api package, but it returns at the option check because no test that calculates packages turns woocommerce_shipping_cost_requires_address on. The tests that do set that option assert show_shipping(), which never calculates a package, and class-wc-cart-default-shipping-method-test.php builds its packages by hand rather than through WC_Shipping. Nothing asserts what survives the strip:
- With the option off, nothing is removed
- With it on and the address incomplete, only method ids in
get_local_pickup_method_ids()remain - With it on and the address complete, nothing is removed
- The early return for
shortcodecontext
One row deliberately left out
Pickup enabled with zero enabled locations produces a calculated package with an empty rate list rather than the ordinary no-address state. The short-circuit in WC_Cart::show_shipping() (class-wc-cart.php:1866) is itself decided and already pinned, for woocommerce#62785. What is undecided is what the shopper should then see, so that outcome gets a report rather than a test that freezes it.
Conventions
The seams in scope are woocommerce_cart_ready_to_calc_shipping and the shipping-calculator field filters. Pin that they are honoured, not that the outcome is fixed.
Integration and unit tests only, no E2E.
Source: woocommerce/woocommerce