Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions inc/tax/class-tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

add_action('wu_page_wp-ultimo-settings_load', [$this, 'add_sidebar_widget']);

add_filter('wu_cart_applicable_tax_rates', [$this, 'apply_universal_tax_rate'], 10, 4);

if ($this->is_enabled()) {
add_action('wp_ultimo_admin_pages', [$this, 'add_admin_page']);

Expand Down Expand Up @@ -90,6 +92,42 @@
}
}

/**
* 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 {

Check warning on line 105 in inc/tax/class-tax.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The method parameter $cart is never used

Check warning on line 105 in inc/tax/class-tax.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The method parameter $tax_category is never used

Check warning on line 105 in inc/tax/class-tax.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

The method parameter $country is never used

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,
]

Check failure on line 124 in inc/tax/class-tax.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

There should be a comma after the last array item in a multi-line array.
];
}

return $rates;
}
Comment on lines +95 to +129
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.


/**
* Register tax settings.
*
Expand Down Expand Up @@ -132,6 +170,37 @@
],
]
);

wu_register_settings_field(
'taxes',
'enable_universal_tax',
[
'title' => __('Enable Universal Tax', 'ultimate-multisite'),
'desc' => __('Enable a fallback universal tax rate when no country-specific rates match.', 'ultimate-multisite'),
'type' => 'toggle',
'default' => 0,
'require' => [
'enable_taxes' => 1,
],
]
);

wu_register_settings_field(
'taxes',
'universal_tax_rate',
[
'title' => __('Universal Tax Rate (%)', 'ultimate-multisite'),
'desc' => __('Tax rate applied when no country-specific rate matches.', 'ultimate-multisite'),
'type' => 'number',
'default' => 10,
'min' => 0,
'max' => 100,
'require' => [
'enable_taxes' => 1,

Check warning on line 199 in inc/tax/class-tax.php

View workflow job for this annotation

GitHub Actions / Code Quality Checks

Array double arrow not aligned correctly; expected 9 space(s) between "'enable_taxes'" and double arrow, but found 5.
'enable_universal_tax' => 1,
],
]
);
}

/**
Expand Down
62 changes: 41 additions & 21 deletions lang/ultimate-multisite.pot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2025-11-21T19:45:32+00:00\n"
"POT-Creation-Date: 2025-11-30T09:27:56+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.12.0\n"
"X-Domain: ultimate-multisite\n"
Expand Down Expand Up @@ -3631,7 +3631,7 @@ msgid "Tax description. This is shown on invoices to end customers."
msgstr ""

#: inc/admin-pages/class-payment-edit-admin-page.php:802
#: inc/tax/class-tax.php:204
#: inc/tax/class-tax.php:273
msgid "Tax Rate"
msgstr ""

Expand Down Expand Up @@ -4126,8 +4126,8 @@ msgstr ""
#: inc/list-tables/class-line-item-list-table.php:216
#: inc/tax/class-dashboard-taxes-tab.php:63
#: inc/tax/class-dashboard-taxes-tab.php:151
#: inc/tax/class-tax.php:104
#: inc/tax/class-tax.php:105
#: inc/tax/class-tax.php:142
#: inc/tax/class-tax.php:143
#: views/checkout/templates/order-summary/simple.php:188
msgid "Taxes"
msgstr ""
Expand Down Expand Up @@ -4937,7 +4937,7 @@ msgstr ""
#: inc/admin-pages/class-tax-rates-admin-page.php:75
#: inc/admin-pages/class-tax-rates-admin-page.php:86
#: inc/admin-pages/class-tax-rates-admin-page.php:97
#: inc/tax/class-tax.php:148
#: inc/tax/class-tax.php:217
#: views/taxes/list.php:12
msgid "Tax Rates"
msgstr ""
Expand Down Expand Up @@ -18472,60 +18472,80 @@ msgstr ""
msgid "Taxes Collected"
msgstr ""

#: inc/tax/class-tax.php:115
#: inc/tax/class-tax.php:113
msgid "Universal Tax"
msgstr ""

#: inc/tax/class-tax.php:153
msgid "Enable Taxes"
msgstr ""

#: inc/tax/class-tax.php:116
#: inc/tax/class-tax.php:154
msgid "Enable this option to be able to collect sales taxes on your network payments."
msgstr ""

#: inc/tax/class-tax.php:126
#: inc/tax/class-tax.php:164
msgid "Inclusive Tax"
msgstr ""

#: inc/tax/class-tax.php:127
#: inc/tax/class-tax.php:165
msgid "Enable this option if your prices include taxes. In that case, Ultimate Multisite will calculate the included tax instead of adding taxes to the price."
msgstr ""

#: inc/tax/class-tax.php:189
#: inc/tax/class-tax.php:178
msgid "Enable Universal Tax"
msgstr ""

#: inc/tax/class-tax.php:179
msgid "Enable a fallback universal tax rate when no country-specific rates match."
msgstr ""

#: inc/tax/class-tax.php:192
msgid "Universal Tax Rate (%)"
msgstr ""

#: inc/tax/class-tax.php:193
msgid "Tax rate applied when no country-specific rate matches."
msgstr ""

#: inc/tax/class-tax.php:258
msgid "Regular"
msgstr ""

#: inc/tax/class-tax.php:232
#: inc/tax/class-tax.php:301
#: inc/ui/class-site-actions-element.php:184
#: views/limitations/plugin-selector.php:80
msgid "Default"
msgstr ""

#: inc/tax/class-tax.php:295
#: inc/tax/class-tax.php:364
msgid "You don't have permission to alter tax rates"
msgstr ""

#: inc/tax/class-tax.php:314
#: inc/tax/class-tax.php:383
msgid "No tax rates present in the request"
msgstr ""

#: inc/tax/class-tax.php:346
#: inc/tax/class-tax.php:415
msgid "Tax Rates successfully updated!"
msgstr ""

#: inc/tax/class-tax.php:386
#: inc/tax/class-tax.php:390
#: inc/tax/class-tax.php:455
#: inc/tax/class-tax.php:459
msgid "Manage Tax Rates"
msgstr ""

#: inc/tax/class-tax.php:394
#: inc/tax/class-tax.php:463
msgid "Add different tax rates depending on the country of your customers."
msgstr ""

#: inc/tax/class-tax.php:400
#: inc/tax/class-tax.php:469
msgid "You need to activate tax support first."
msgstr ""

#: inc/tax/class-tax.php:408
#: inc/tax/class-tax.php:414
#: inc/tax/class-tax.php:418
#: inc/tax/class-tax.php:477
#: inc/tax/class-tax.php:483
#: inc/tax/class-tax.php:487
msgid "Manage Tax Rates →"
msgstr ""

Expand Down
Loading