Page 1 of 2
Loading Tax rates into hooks-sitwide
Posted: Fri Aug 29, 2025 7:19 am
by Portman
Hi, I want to load the tax_rate for a product for US customers for a hook I am trying to make… this is to show the tax (tariff) rate before being applied to order total.
I was trying to look for an example of this in existing code but couldn’t find one…. Could someone point me in the right direction for this?
Re: Loading Tax rates into hooks-sitwide
Posted: Fri Aug 29, 2025 9:22 am
by burt
Pls explain more clearly what you have done.
- where is the data you want to display...stored.
And what you want to end up with.
- where you want the stored data displayed.
- for whom you want the data displayed.
Re: Loading Tax rates into hooks-sitwide
Posted: Sat Aug 30, 2025 6:53 am
by Portman
OK.... here is an example of what I want to do ;

My site is set up so that people can only see prices if they are logged in as an aproved wholesaler so I know their country to see this info ....
this +0% T&D only comes up for my US customers (something similar happens for my AU customers but that is just +GST if they are AU - which is just a static 10% so no need to add that bit because everyone knows it)
Because I am going to have multiple tarrif rates including 0% I want my customers to know what they will be up for before they get to checkout ... so I want to load the correct tax_rate from the tax_rates table for each item ...
so basically ;
If Customer = US then Display "+ '$tax_rate'% T+D"
I can't share the code for this as it is someone elses work that I amtoying with but basically this is in a sitewide hook inside a public function
Re: Loading Tax rates into hooks-sitwide
Posted: Sat Aug 30, 2025 12:37 pm
by raiwa
You can easy adapt my Prices with tax info addon for your needs :
app.php/addons/free_addon/prices_with_tax_info
if you have "Display prices with tax" set to "false", you need to change one line in the hook:
templates\override\includes\hooks\shop\siteWide\priceTax.php line 74:
Code: Select all
if ( $products_tax == '0' || DISPLAY_PRICE_WITH_TAX == 'false' ) {
change to:
or complete remove the condition to show "+0% T&D" instead of "Tax excl."
Then edit the text file to show "+xx% T&D" instead of "xx% tax incl."
Re: Loading Tax rates into hooks-sitwide
Posted: Mon Sep 01, 2025 4:18 am
by Portman
Thanks
@raiwa,
That is exacly what I am working on .... the problem is when I use $products_tax I get the tax rate showing up on the order confirmation page - but on thecards on the index page, shopping cart and on the product info page - $product_tax is empty... All I get is "+0% T&D"
I tried to load the tax_rate from the tax_rates table and got it to work on the product info page but not on index, shopping cart and order confirmation pages...
Is there a way around this... I was trying something like this;
Code: Select all
$check_tax_class_query = $GLOBALS['db']->query("SELECT products_tax_class_id FROM products WHERE products_id = '" . (int)$_GET['products_id'] . "'");
$check_tax_class = $check_tax_class_query->fetch_assoc();
$tax_class = $check_tax_class['products_tax_class_id'];
$check_tariff_rate_query = $GLOBALS['db']->query("SELECT tax_rate FROM tax_rates WHERE Tax_zone_id = '". 2 . "' and tax_class_id = '". $tax_class . "'"); // Tax Zone 2 is USA
$check_tariff_rate = $check_tariff_rate_query->fetch_assoc();
$tariff_rate = $check_tariff_rate['tax_rate'];
Re: Loading Tax rates into hooks-sitwide
Posted: Mon Sep 01, 2025 7:09 am
by raiwa
Why do you want to invent the wheel again? Just use my add on.
Re: Loading Tax rates into hooks-sitwide
Posted: Mon Sep 01, 2025 7:54 am
by Portman
Hey
@raiwa;
Sorry, thats what I am trying to say... I am using your addon but I cant get it to work...
I already use it for Australian GST - which just has a static +GST under each each price. So I am trying to make it so the static +GST work for australian customers, using TAX_BELOW_PRICE_EXCLUDING_TAX, but then also have it working for USA Tariffs - which I am using the Tax system on the site for.
HOWEVER I have a number of different Tariff rates for different products so I wanted to show the percentage rate for each product....
Working with templates/override/includes/hooks/shop/sitewide/priceTax.php I am using the if statement on line 74 so that the GST for Australian customers work ( ihave to modify the if statement a bit so that it only works for australian customers) , but I am changing the if statement on line 77 to
Code: Select all
if ( DISPLAY_PRICE_WITH_TAX == 'false' && ($_SESSION['wholesale_group']) == '6') {
If that is all I change then the only place that percentage value actually works is in order confirmation.
In what's new , on the product info page, and in the shopping cart $products_tax from line 78 is empty.
see below;

Re: Loading Tax rates into hooks-sitwide
Posted: Mon Sep 01, 2025 9:06 am
by raiwa
I have updated the addon and included support for Display prices set to false. Your wholesale group support is obviously not included. Please update and adjust for your needs.
Re: Loading Tax rates into hooks-sitwide
Posted: Mon Sep 01, 2025 11:17 am
by Portman
Thanks @raiwa
I have applied the update and am still having the same problems... I will drop the code I am working on in a private message
Re: Loading Tax rates into hooks-sitwide
Posted: Mon Sep 01, 2025 12:23 pm
by raiwa
If $products_tax is zero, your tax setup is wrong. If you have the tax zones and rates correct setup like @ecartz suggested, the addon will show the tax rates everywhere.
To check it, you could temporary switch "Display prices with tax" to "true" and see if you get in the listings the Product prices shown with tax.