Loading Tax rates into hooks-sitwide

Open to all! Ask other shopowners for help.
User avatar
Portman
Contributor
Posts: 158
Joined: Mon Mar 08, 2021 1:04 am
Phoenix Version: v1.0.8.20
Has thanked: 29 times
Been thanked: 4 times

Loading Tax rates into hooks-sitwide

Post 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?


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4546
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 412 times

Re: Loading Tax rates into hooks-sitwide

Post 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.
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
Portman
Contributor
Posts: 158
Joined: Mon Mar 08, 2021 1:04 am
Phoenix Version: v1.0.8.20
Has thanked: 29 times
Been thanked: 4 times

Re: Loading Tax rates into hooks-sitwide

Post by Portman »

OK.... here is an example of what I want to do ;

ImageImage

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
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Loading Tax rates into hooks-sitwide

Post 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:

Code: Select all

    			if ( $products_tax == '0') {
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."
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
User avatar
Portman
Contributor
Posts: 158
Joined: Mon Mar 08, 2021 1:04 am
Phoenix Version: v1.0.8.20
Has thanked: 29 times
Been thanked: 4 times

Re: Loading Tax rates into hooks-sitwide

Post 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'];
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Loading Tax rates into hooks-sitwide

Post by raiwa »

Why do you want to invent the wheel again? Just use my add on.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
User avatar
Portman
Contributor
Posts: 158
Joined: Mon Mar 08, 2021 1:04 am
Phoenix Version: v1.0.8.20
Has thanked: 29 times
Been thanked: 4 times

Re: Loading Tax rates into hooks-sitwide

Post 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;
Image
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Loading Tax rates into hooks-sitwide

Post 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.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
User avatar
Portman
Contributor
Posts: 158
Joined: Mon Mar 08, 2021 1:04 am
Phoenix Version: v1.0.8.20
Has thanked: 29 times
Been thanked: 4 times

Re: Loading Tax rates into hooks-sitwide

Post 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
raiwa
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Loading Tax rates into hooks-sitwide

Post 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.
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply