Skip to content

Conversation

@mahyarrezghi
Copy link
Contributor

@mahyarrezghi mahyarrezghi commented Nov 30, 2025

  • Add enable_universal_tax setting toggle
  • Add universal_tax_rate setting (0-100%)
  • Implement apply_universal_tax_rate filter
  • Update translations for new strings
  • Apply universal rate when no country-specific rates match

Summary by CodeRabbit

  • New Features
    • Universal tax rate feature now available, allowing site administrators to enable and configure a default tax rate percentage (0-100%) through new admin settings.
    • Tax system enhanced with automatic fallback mechanism to apply universal tax rates when country-specific tax rates are unavailable.

✏️ Tip: You can customize this high-level summary in your review settings.

- Add enable_universal_tax setting toggle
- Add universal_tax_rate setting (0-100%)
- Implement apply_universal_tax_rate filter
- Update translations for new strings
- Apply universal rate when no country-specific rates match
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 30, 2025

Walkthrough

Adds universal fallback tax rate mechanism to the tax system. Introduces new filter hook and method to apply a universal tax rate when no country-specific rates exist. Extends tax settings with admin fields to enable and configure the universal tax rate globally.

Changes

Cohort / File(s) Change Summary
Universal Tax Rate Logic
inc/tax/class-tax.php
Registers new filter hook wu_cart_applicable_tax_rates and introduces apply_universal_tax_rate() method to inject a universal fallback tax rate when no country-specific rates exist and universal tax is enabled. Adds two new admin fields: enable_universal_tax (toggle) and universal_tax_rate (0-100 numeric) with conditional dependencies.
Translation Updates
lang/ultimate-multisite.pot
Updates POT header timestamp and adds new translation strings for universal tax feature ("Universal Tax", "Universal Tax Rate (%)", "Enable Universal Tax"). Adjusts line number references for existing tax-related strings due to code additions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify filter hook registration priority and integration with tax rate application flow
  • Confirm admin field dependencies correctly gate visibility and validation
  • Validate universal rate fallback logic (conditions for empty rates, tax collection, and enablement)
  • Check that universal rate ID, title, country wildcard, and priority fields are correctly structured

Poem

🐰 A rate so fair for every land,
When nations flee, our tax takes stand,
A universal shield, we proudly say,
From corner shop to grand café! 💰

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(tax): add universal tax fallback feature' directly and clearly describes the main change: adding a universal tax fallback mechanism. It matches the PR objectives and the primary code changes in class-tax.php.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
inc/tax/class-tax.php (1)

174-203: New universal tax settings are consistent with behavior; optional style fix for alignment warning

The two new settings fields look coherent with the runtime logic:

  • enable_universal_tax is a toggle gated on enable_taxes, matching the runtime wu_should_collect_taxes() + enable_universal_tax checks.
  • universal_tax_rate:
    • Numeric 0–100 with a default of 10%, consistent with the fallback default in apply_universal_tax_rate.
    • Properly requires both enable_taxes and enable_universal_tax, so it only surfaces when relevant.
    • Copy and translation domain match the rest of the file.

The only remaining item is a non-blocking style warning from the code quality checks about double-arrow alignment on the 'enable_taxes' key at line 199. If you want to satisfy that sniff, you can adjust spacing, e.g.:

-					'enable_taxes'     => 1,
-					'enable_universal_tax' => 1,
+					'enable_taxes'         => 1,
+					'enable_universal_tax' => 1,

Functionally everything here aligns with the new feature’s intent.

lang/ultimate-multisite.pot (1)

18475-18510: Universal tax strings are clear; consider tiny wording tweak

The new strings for the universal fallback tax feature (“Universal Tax”, “Enable Universal Tax”, “Universal Tax Rate (%)”, and their descriptions) are clear and aligned with the feature’s behavior.

One optional polish point for consistency/grammar between the two descriptions:

  • Current:
    • “Enable a fallback universal tax rate when no country-specific rates match.”
    • “Tax rate applied when no country-specific rate matches.”

Consider updating the first to singular for consistency:

-Enable a fallback universal tax rate when no country-specific rates match.
+Enable a fallback universal tax rate when no country-specific rate matches.

This would need to be changed in the PHP source (inc/tax/class-tax.php:179), then the POT regenerated.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0df6d71 and a3f97e8.

📒 Files selected for processing (2)
  • inc/tax/class-tax.php (3 hunks)
  • lang/ultimate-multisite.pot (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
inc/tax/class-tax.php (2)
inc/functions/tax.php (1)
  • wu_should_collect_taxes (20-23)
inc/functions/settings.php (2)
  • wu_get_setting (37-40)
  • wu_register_settings_field (88-91)
🪛 GitHub Check: Code Quality Checks
inc/tax/class-tax.php

[failure] 124-124:
There should be a comma after the last array item in a multi-line array.


[warning] 105-105:
The method parameter $cart is never used


[warning] 105-105:
The method parameter $tax_category is never used


[warning] 105-105:
The method parameter $country is never used


[warning] 199-199:
Array double arrow not aligned correctly; expected 9 space(s) between "'enable_taxes'" and double arrow, but found 5.

🪛 PHPMD (2.15.0)
inc/tax/class-tax.php

105-105: Avoid unused parameters such as '$country'. (undefined)

(UnusedFormalParameter)


105-105: Avoid unused parameters such as '$tax_category'. (undefined)

(UnusedFormalParameter)


105-105: Avoid unused parameters such as '$cart'. (undefined)

(UnusedFormalParameter)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: PHP 7.4
  • GitHub Check: PHP 8.4
  • GitHub Check: cypress (8.1, chrome)
  • GitHub Check: cypress (8.2, chrome)
🔇 Additional comments (3)
inc/tax/class-tax.php (1)

35-35: Filter registration for universal tax fallback looks correct

Hooking apply_universal_tax_rate into wu_cart_applicable_tax_rates with priority 10 and 4 accepted args matches the described design and keeps the fallback logic centralized in the tax class.

lang/ultimate-multisite.pot (2)

12-14: POT header date update is fine

POT-Creation-Date reflects the new extraction time and is consistent with a regenerated POT; no action needed.


3637-3638: Tax-related source reference additions look consistent

The extra references for existing strings like “Tax Rate”, “Taxes”, and “Tax Rates” pointing into inc/tax/class-tax.php correctly align these labels with the new tax logic and UI, without altering the translatable text. No further changes required here.

Also applies to: 4129-4131, 4940-4943, 18515-18551

Comment on lines +95 to +129
/**
* Applies universal tax rate when no specific rates are found.
*
* @since 2.0.0
* @param array $rates Tax rates.
* @param string $country Country code.
* @param string $tax_category Tax category.
* @param object $cart Cart object.
* @return array
*/
public function apply_universal_tax_rate(array $rates, string $country, string $tax_category, $cart): array {

if (empty($rates) && wu_should_collect_taxes() && wu_get_setting('enable_universal_tax', false)) {
$universal_rate = wu_get_setting('universal_tax_rate', 10);

$rates = [
[
'id' => 'universal-' . uniqid(),
'title' => __('Universal Tax', 'ultimate-multisite'),
'country' => '*',
'state' => '',
'city' => '',
'tax_type' => 'percentage',
'tax_amount' => $universal_rate,
'tax_rate' => $universal_rate,
'priority' => 1,
'compound' => false,
'type' => 'regular',
'rate' => $universal_rate,
]
];
}

return $rates;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Universal tax fallback logic is sound; fix trailing comma lint + consider unused param warnings

Functionally this method does what the PR describes:

  • Only applies when there are no existing rates, taxes should be collected, and universal tax is enabled.
  • Pulls the rate from settings (default 10) and builds a rate array consistent with existing tax rate structures (id, title, country wildcard, percentage type, rate fields, priority, etc.).
  • Returns the original $rates unchanged when the condition is not met.

Two minor points:

  1. Trailing comma in multiline array (blocks code quality check)
    The last element of the inner array ('rate' => $universal_rate) is missing a trailing comma, which the code-quality check flags as a failure. You can fix it like this:
-					'rate'       => $universal_rate,
-				]
+					'rate'       => $universal_rate,
+				],
  1. Unused parameters in the callback
    $country, $tax_category, and $cart are intentionally unused but required by the filter signature. I’d keep them for future-proofing and hook compatibility; if PHPMD noise becomes an issue, you could add a @SuppressWarnings(PHPMD.UnusedFormalParameter) annotation on the method docblock rather than changing the signature.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Applies universal tax rate when no specific rates are found.
*
* @since 2.0.0
* @param array $rates Tax rates.
* @param string $country Country code.
* @param string $tax_category Tax category.
* @param object $cart Cart object.
* @return array
*/
public function apply_universal_tax_rate(array $rates, string $country, string $tax_category, $cart): array {
if (empty($rates) && wu_should_collect_taxes() && wu_get_setting('enable_universal_tax', false)) {
$universal_rate = wu_get_setting('universal_tax_rate', 10);
$rates = [
[
'id' => 'universal-' . uniqid(),
'title' => __('Universal Tax', 'ultimate-multisite'),
'country' => '*',
'state' => '',
'city' => '',
'tax_type' => 'percentage',
'tax_amount' => $universal_rate,
'tax_rate' => $universal_rate,
'priority' => 1,
'compound' => false,
'type' => 'regular',
'rate' => $universal_rate,
]
];
}
return $rates;
}
/**
* Applies universal tax rate when no specific rates are found.
*
* @since 2.0.0
* @param array $rates Tax rates.
* @param string $country Country code.
* @param string $tax_category Tax category.
* @param object $cart Cart object.
* @return array
*/
public function apply_universal_tax_rate(array $rates, string $country, string $tax_category, $cart): array {
if (empty($rates) && wu_should_collect_taxes() && wu_get_setting('enable_universal_tax', false)) {
$universal_rate = wu_get_setting('universal_tax_rate', 10);
$rates = [
[
'id' => 'universal-' . uniqid(),
'title' => __('Universal Tax', 'ultimate-multisite'),
'country' => '*',
'state' => '',
'city' => '',
'tax_type' => 'percentage',
'tax_amount' => $universal_rate,
'tax_rate' => $universal_rate,
'priority' => 1,
'compound' => false,
'type' => 'regular',
'rate' => $universal_rate,
],
];
}
return $rates;
}
🧰 Tools
🪛 GitHub Check: Code Quality Checks

[failure] 124-124:
There should be a comma after the last array item in a multi-line array.


[warning] 105-105:
The method parameter $cart is never used


[warning] 105-105:
The method parameter $tax_category is never used


[warning] 105-105:
The method parameter $country is never used

🪛 PHPMD (2.15.0)

105-105: Avoid unused parameters such as '$country'. (undefined)

(UnusedFormalParameter)


105-105: Avoid unused parameters such as '$tax_category'. (undefined)

(UnusedFormalParameter)


105-105: Avoid unused parameters such as '$cart'. (undefined)

(UnusedFormalParameter)

🤖 Prompt for AI Agents
In inc/tax/class-tax.php around lines 95 to 129, the trailing comma is missing
on the last element of the inner rate array and PHPMD may flag unused parameters
($country, $tax_category, $cart); add a trailing comma after the 'rate' =>
$universal_rate array entry to satisfy the linter, and keep the unused
parameters but add a docblock annotation like
@SuppressWarnings(PHPMD.UnusedFormalParameter) to the method docblock to silence
PHPMD warnings while preserving the filter signature.

Copy link
Collaborator

@superdav42 superdav42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd rather implement this by adding a new option to the country drop down, "Apply to all countries" that could be chosen on the tax rates configuration page. It would probably be simpler to implement and wouldn't need a new setting field. Did you consider this approach?

@mahyarrezghi
Copy link
Contributor Author

My thinking was: since the user has to go to the tax settings to enable it first, they should also be able to enable universal tax rates there, instead of having to go to a separate page.

@superdav42
Copy link
Collaborator

My thinking was: since the user has to go to the tax settings to enable it first, they should also be able to enable universal tax rates there, instead of having to go to a separate page.

I understand but I want it to be in tax rates configuration page. I don't want to add more settings on the settings page unless they are going to be used by most users. A universal tax seems like an advanced option that belongs on the tax rates page. I've never seen any other software use a "universal tax" so it seems like a foreign concept and would confuse many users.

@mahyarrezghi
Copy link
Contributor Author

I've never seen any other software use a "universal tax" so it seems like a foreign concept and would confuse many users.

Makes sense! I'll edit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants