Build Your Own Business Website header image

How to Setup California Local Sales Tax in Shopp Part 2 – the shopp_cart_taxrate() Filter

Difficulty Level -

Filed Under Topics - ,

Listed Under Lesson Subjects -

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

In this session we discuss the use of the shopp_cart_taxrate_() filter to filter the tax rates. The filter grabs the value of the rate and lets us change the value. We create a conditional statement so that if it is California it will return a specific number otherwise it returns the default rate.

Video Transcript

This is an entirely custom function so there is set Shopp page or Shopp file that we’re going to be editing for this. We’re going to create our own entirely separate function.

On this site, this is the Shopp test project and under Thesis 1.8.4, under custom, this is where I’m going to put this. I’m going to create a new file called Shopp custom functions. Hit finish. Okay and actually, I’m just going to say this file contains custom functions related to the Shopp plugin. Okay so we’ve got this new file called Shopp custom functions and in order for this to fire at any place, we need to include it in our custom functions.php file.

So what we’re going to do is open up custom functions.php and up here at the top, we’re going to say include once. Then since it’s in the exactly the same location, just copy that. We don’t need to add any… so include once Shopp custom functions.php. Okay and so that’s all we need to do here, is make sure that we have included this file. Go ahead and hit save. Hit save again and we have the beginning of this process.

Now we’re going to create a new function and we’ll name this… let’s see, California sales tax. Let’s see, byob California sales tax. Okay, there’s our new function and this new function goes to a filter. That filter is calculate tax, I believe, so let’s come over here to the Shopp… I’ve been meandering through Shopp quite a bit here today. Let’s see, let’s go to Shopp APIs and let’s look at filters, filter hooks. And I think it’s calculate tax. Shopp… let’s see, let’s just search for tax. Yeah, it’s not calculate tax. It’s Shopp cart tax rate. That’s the name of the filter.

What we’re going to do then is Shopp cart tax rate. We’re going to add this filter, Shopp cart tax rate and we’re going to replace this with the actual name of the callback function. Okay and now, this function, this is going to filter the tax rate.

Now before we get too far down the road on it, we want to make sure that what we’ve done is we’ve captured the rate. That actually needs to go inside of there. And the way this works is like any other filter. First, we’re going to bring the value of the rate in and then we are going to return the new value of this filter .And so if left alone, the filter returns the rate. If we don’t put anything in here at all, the rate’s going to be erased because we haven’t told it to do anything.

So what we’re going to say here is control V rate equals rate. So we’ve created a variable called rate and we’ve placed the value of rate in that variable. Then we’re going to say if the state is California… now, I’m just going to write this out at the moment, because this is not actually right. But if state equals California then do something specifically. Else… or actually, there’s no such thing as else and then we just return rate. Okay and then actually, pardon me… and then rate will equal some number.

Okay so if the state is California then you’re going to return some number in the rate. Otherwise, the value of rate is going to be returned. That’s how this filter works. It grabs the value of the rate and it lets us change that value. But if we don’t change the value, we’ve got to return it unedited. So that’s what this return rate is doing here.

Okay now this is actually not the correct syntax. It’s the correct conceptual syntax but it’s not actually the correct syntax. Because what we need to do is we need to identify whether or not the state is actually California. I’m going to open up my example of this because I did this already for a fee. I was paid to do this and themes a while ago. Let’s see, custom and then we have our store functions.

So in this case here, we’ve got this long list of city and of values, right? We’re going to create that from scratch here in just a minute. But once we get that long list of city and values, we need to grab the global Shopp parameter then we’re going to say state equal Shopp order shipping state and then if state equals California. Or if state doesn’t equal California, return the rate. That’s what’s happening here. We’re probably going to do it differently.

Come back over to this. Okay so global Shopp, rate equals rate and let’s just copy that part of it. So state equals Shopp order shipping state. This is how you reference that value out of the global variable Shopp. If the state is not equal to California then return the rate. Actually, we can go ahead and get rid of this information here. If the state is not equal to California, return the rate.

That’s actually not a bad way to do it really because it doesn’t go any further. Once it hits that return statement, it stops. So that’s actually a good way to do it. If the state is not equal to California, return the rate. If the state is equal to California then what we’re going to do is test for the city. Well actually, at the moment, we’ll say here that $rate equals… let’s see, 10 and return rate. Return $rate. Okay, this is just a test, right?

What we’re going to do is if the state’s not equal to California then it’s going to return the rate. If the state is equal to California then it’s going to return 10% actually so we’re overwriting that one. If we hit save, this is how I like to simplify the process. So start by just testing to make sure that the function works and then add complexity to the function as I go along.

So let’s see, thesisshopp.com. There we go. Wait for it to connect. Okay, wp-content, themes, thesis_184, custom and then we’re just going to… custom functions… h, it’s because I’m in the wrong location here. Okay, my mistake. Let’s see, let’s go back to the Site Manager and let’s do a copy of this. Copy of thesisshopp.com and then on this copy, we’re actually going to go to my project that I have of this. So where is Shopp test? Here we go. Do that again.

Okay so wp-content, themes, thesis_184, custom, there we go. There are my two new functions. Upload that to thesisshopp, come back over to our test here. Let’s see, edit the shopping cart. Okay actually, if we hit estimate shipping and taxes, that should go up to $3, I believe. Oh no, it’s $300 because the value, it needs to be a decimal. I thought it was a whole number. That’s interesting. I did not realize it was… that’s fine.

Okay so it needs to go to its 0.10 and in fact, it’s 0.010. Okay, we refresh this. We estimate shipping and taxes. Yeah, now it’s $0.30. It should be $3. You know, I guess I’m getting my decimals wrong. Okay, that’s what it is.

So the basic thing works here, right? We test to see if it’s California and if it’s in California then we return. If it’s not in California then we return the standard rate and if it is in California then we return a flat rate of 10%.

If we choose 98020 which is the Edmonds zip code, estimate shipping and taxes, we’re going to get a different value because I have that 98020. Estimate shipping and taxes, $2.77 because I have the Washington taxes set at 9.25%, right? So it’s substituting that value if it’s California, using a California zip code.

0 Comments… add one
0 comments… add one

Leave a Comment