Forum

Thread tagged as: Shop

A Tax Solution for Multi-Region Countries (US, Canada etc.)

Hello,
I thought I'd post the solution that I used to charge the appropriate tax based on US STATE and/or COUNTY (a subset of state). This could be applied to Canadian provinces, or in any case where tax needs to be calculated at a level lower than address COUNTRY.

I'm sure there are more enlightened ways to do this, but here's what I did--

In my address capture forms I added a select field containing the counties that that I want customers to choose from.

i.e. <perch:input id="county" type="select" options="COUNTY1, COUNTY2, COUNTY3" />

**n.b. Because I only need to collect tax in one state at the moment, I used some jQuery to only show the county select box when a customer selects that state from a dropdown.

I'm in a state where there are 70 counties, but only 11 unique tax rates between them.
Instead of adding each county as a Tax Location in Perch, I created 11 Tax Locations, one for each unique rate, and one "tax exempt" location with a rate of 0%.

Then to apply the appropriate rate based on the customer's shipping address...
An example:
Where 10, 11, 12 correspond to the tax locationID
and
shipping_county.html is <perch:shop id="shipping_county" />
shipping_state.html is <perch:shop id="shipping_state" />
(^ I had trouble getting these order address values with straight-up page functions so I did it this way.)

<?php

$shipping_county = perch_shop_order_addresses(array('template'=>'shop/addresses/shipping_county.html'), true);
$shipping_state = perch_shop_order_addresses(array('template'=>'shop/addresses/shipping_state.html'), true);
$tax_exempt = 10;

$rate_one = 11;
$rate_two = 12;

$array_one = array("COUNTY1", "COUNTY2");
$array_two = array("COUNTY3");

if ($shipping_state == 'STATE1') {

if (in_array($shipping_county, $array_one)) {
    perch_shop_set_tax_location($rate_one);
}

if (in_array($shipping_county, $array_two)) {
    perch_shop_set_tax_location($rate_two);
}

} else {
perch_shop_set_tax_location($tax_exempt);
};

?>
Olympia Kyriakides

Olympia Kyriakides 1 points

  • 4 years ago