From b64b66ccedbd68f6a58601d4c64a3951527efa4a Mon Sep 17 00:00:00 2001 From: David Stone Date: Thu, 26 Mar 2026 01:31:51 -0600 Subject: [PATCH] fix(tax): skip wu_get_country_states() for wildcard '*' country rates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a tax rate has country='*' (Apply to all countries), calling wu_get_country_states('*') is meaningless — there are no states for a wildcard country. Guard the call so wildcard rates receive an empty state_options array instead of a spurious lookup. The rest of the universal tax fallback feature was already in place on main: - wu_get_applicable_tax_rates() returns '*' rates as a catch-all fallback when no country-specific rate matches (inc/functions/tax.php) - The country dropdown in the Tax Rates UI includes 'Apply to all countries' as the first option with value='*' (views/taxes/list.php) - Comprehensive unit tests for the wildcard fallback behaviour (tests/WP_Ultimo/Functions/Tax_Functions_Test.php) Closes #511 --- inc/tax/class-tax.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/tax/class-tax.php b/inc/tax/class-tax.php index 322f0bd9f..e151636a8 100644 --- a/inc/tax/class-tax.php +++ b/inc/tax/class-tax.php @@ -248,7 +248,14 @@ public function get_tax_rates($fetch_state_options = false) { function ($rate) use ($fetch_state_options) { if ($fetch_state_options) { - $rate['state_options'] = wu_get_country_states($rate['country'], 'slug', 'name'); + /* + * Rates with country='*' (Apply to all countries) are wildcard + * fallbacks and have no meaningful state list — skip the lookup + * to avoid passing '*' to wu_get_country_states(). + */ + $rate['state_options'] = ('*' !== $rate['country']) + ? wu_get_country_states($rate['country'], 'slug', 'name') + : []; } $rate['tax_rate'] = is_numeric($rate['tax_rate']) ? $rate['tax_rate'] : 0;