From time to time, we get people asking how they can remove the Shipping Calculator feature in WP eCommerce. You’ve probably come across these before: before calculating shipping, you have to enter your ZIP code or state or something like that. Pretty standard fare.
The problem, of course, is that it can be an unnecessary extra step, causing friction in the checkout process. For example, it’s totally unnecessary if you only ship to one country and ship with a flat rate to that country, it makes no sense to have a shipping calculator. So – let’s dig in!
If you haven’t moved your shopping cart template file to your active theme folder, now’s the time to do that 🙂 In a normal installation, you’ll have a shipping calculator that looks something like this:
Step 1: Presentation
The first step is removing the calculator from your theme. There’s not a single chunk of code to remove, but a few. Thankfully, they’re all right around the same place.
- Remove the “Calculate Shipping Price” header.
- Remove built-in error/notice conditions, country and ZIP drop-downs.
At this point, the shipping calculator should be visibly absent. Woohoo!
Step 2: Functional Logic
Even though we’re looking good now, we’re not working good. That’s a problem. The first thing you’ll notice is that when you hit purchase, you get scrolled back to the top of the page with a message that says you need to calculate shipping. While we have filters that control whether or not you should force that sliding UX, we have even better filters to control whether or not to force a recalculation. The following filter in a plugin
This gets us one step closer, but astute observers may note that shipping quotes no longer show up. This is because none are calculated. The following code ensures a rate is calculated:
If you’re only using a single shipping method with a single rate (as most folks who request this seem to be), you’re all set. The steps above are all you need to do to kill off the shipping calculator for good 🙂
If you’re using multiple shipping methods? Well, that gets trickier, and depends on which methods you’re using. If this is an issue you’re facing, I’d be more than happy to chat with you about it.
As a non programer this answers a question and raises a question.
You have the following statement:
The following filter in a plugin
Does this mean I need to make a custom plugin, or can this be inserted into a page on the site?
Hi Wade,
Great question! We generally recommend creating a functionality plugin for changes like this, changes that are custom to your site that you might like to have persist if you were to change themes.
Here’s a great tutorial on how you would go about that: http://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/
Hope that helps!
Hi’
i’ve followed the above instructions but get the error plugin disabled, it doesn’t like the 2nd code snippet:
add_action( ‘template_redirect’, function() {
if ( is_page( wpsc_get_the_post_id_by_shortcode( ‘[checkout]’ ) ) ) {
wpsc_update_location();
}
} );
Does that code need to be between separate php brackets? I’ve tried but no luck, Could you possibly share the full code?
Hi Cath,
It’s very possible that you might be running a server with PHP 5.2, rather than 5.3+. This type of function, sometimes called a closure or anonymous function, is a feature of PHP 5.3+. You might confirm this with your host?
Hi Justin,
I’m trying to follow the above steps and have had a go at removing what I think are the correct sections from wpsc-shopping_cart_page.php, but I would like to add the Functional Logic section directly to my functions.php file.
Is it possible you could add a little more clarification on exactly what to remove from the shopping cart page and whether I can add to functions.php please?
Hi Amanda!
Great question (sorry for the delayed response!)
You can definitely add the code to your functions.php file.
As far as which sections to remove from the shopping cart page, those are outlined in Step 1.
Hope that helps!
Your second code snippet is missing a third closing bracket in the if statement, causing a syntax error.
Thanks Joris, updated!
Thanks Justin, that was really helpful.
Created a plugin as suggested and activated it – hey presto – no more requests for recalculations.
Im now going to make this apply ONLY if simple_shipping is the selected method.
Wish me luck!