Shipping tests: shipping tax
What this covers
The merchant configures tax, and the shopper should see the right tax on the shipping line in the Cart and Checkout blocks. PHP and client.
Expected behaviour
- No tax when tax is switched off
- A taxable method is taxed and a non-taxable one is not
- Choosing pickup taxes at the store address rather than the shopper's
- A location with its own address taxes there
- A coupon lowers the rate and therefore the tax
- Totals are shown including or excluding tax as configured
Where it breaks
- A VAT-exempt customer pays no shipping tax even on a taxable method
- A tax rate exists but is not marked as applying to shipping
- A tax class was deleted while a product still points at it
- The chosen location has no country, so it falls back to the store address
- Reordering the tax class list changes the outcome for a mixed cart
- Rounding to the last unit
Already covered, and more than expected
class-wc-tax-test.php holds 26 tests, most of them about shipping tax specifically: get_shipping_tax_rates() with the standard, reduced and explicitly set classes, with no reduced shipping rates, with no taxable items, with a mixed cart where standard wins, and with an empty cart; get_shipping_tax_class_from_cart_items() over the same ground plus the class hierarchy; the shipping_tax_class filter, including what it receives, that it can modify the class, that it can return null and that behaviour is unchanged without it; and calc_shipping_tax() for inclusive and exclusive pricing, a zero rate, no rates, the filter toggle and the per-item flow. Class resolution and the arithmetic need nothing from us.
ShippingControllerTest holds four filter_order_tax_location() tests, driven by _pickup_location_address meta: the pickup address is used for local_pickup and for legacy_local_pickup, a flat_rate order is left alone, and the location is unchanged when no pickup address was captured. None of the four uses the block's own pickup_location method id.
Checkout.php::test_checkout_preserves_cart_tax_totals runs tax totals through checkout across tax modes and countries, though it inserts its rate with tax_rate_shipping => 0, so shipping is deliberately outside what it proves.
Not covered
- A non-zero shipping tax in the Store API response, anywhere.
Cart.php::test_get_itempinstotal_shippingat'1000'andtotal_shipping_taxat'0'with an emptytax_lines, so the shipping cost is guarded but the tax on it is only ever asserted as absent. The chain from a merchant setting to a shopper-visible shipping tax is unproven end to end filter_taxable_address(), the cart-side twin of the well-tested order-side filter, has no test of its own. Its gate would match inCheckout.php::test_local_pickup_country_validation, which putspickup_location:0inchosen_shipping_methods, but no assertion depends on the address it returns, and no locations are configured there, so the narrowing to a location's own address is not exercised- A taxable method taxed against a non-taxable one left alone
- A VAT-exempt customer paying no shipping tax even on a taxable method
- Choosing pickup taxing at the store address, and a location with its own address taxing there
- A coupon lowering the rate and therefore the tax
One row deliberately left out
filter_taxable_address() gates on LocalPickupUtils::get_local_pickup_method_ids() (ShippingController.php:454), whose list is seeded with the zone method local_pickup (LocalPickupUtils.php:85), and then indexes pickup_location_pickup_locations[$chosen_method_instance] (:456) with that rate's zone instance id. Those are two unrelated numbering spaces, so a shopper choosing local_pickup:3 can be taxed at the address of an unrelated pickup location.
This is reachable on a supported configuration rather than a theoretical one: ShippingController::is_legacy_local_pickup_active() exists precisely because a store that moved to block checkout can keep an enabled zone local_pickup, and the zone admin then invites it to also set up block pickup locations.
Treat it as a bug and file it rather than pinning it. It shares a root with woocommerce/woocommerce#47060: instance id spaces being conflated.
Conventions
The seam in scope is woocommerce_apply_base_tax_for_local_pickup. Pin that it is honoured, not that the outcome is fixed.
Integration and unit tests only, no E2E.
Source: woocommerce/woocommerce