fix(tax): skip wu_get_country_states() for wildcard '*' country rates#512
fix(tax): skip wu_get_country_states() for wildcard '*' country rates#512superdav42 merged 1 commit intomainfrom
Conversation
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
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
|
Note: |
Summary
Completes the universal tax fallback feature (issue #511) by fixing the one missing piece: when a tax rate has
country='*'(Apply to all countries),wu_get_country_states('*')was being called unnecessarily. This guard ensures wildcard rates receive an emptystate_optionsarray instead.What was already in place on
mainThe bulk of the feature was already implemented across three prior PRs/branches:
wu_get_applicable_tax_rates()(inc/functions/tax.php) — already returns*rates as a catch-all fallback when no country-specific rate matches the customer's country. Country-specific rates always take precedence.views/taxes/list.php) — the country dropdown already includes<option value="*">Apply to all countries</option>as the first option.tests/WP_Ultimo/Functions/Tax_Functions_Test.php) — comprehensive tests for wildcard fallback behaviour already exist and pass.What this PR adds
inc/tax/class-tax.php—get_tax_rates()method:When
$fetch_state_options = true(called from the AJAX handler that serves the Tax Rates admin page), passing'*'towu_get_country_states()would attempt to instantiateCountry_*(which doesn't exist), fall back toCountry_Default, and return an empty/meaningless result anyway. The guard makes this explicit and avoids the unnecessary lookup.Testing
php -lpasses on all three tax filesTax_Functions_Test.phpcover the fallback behaviour end-to-end — CI will run theseReferences
feature/universal-tax-rate)