WooCommerce: Set Customer Default Tax Location

The WooCommerce settings allow you to define the default customer tax location (“Calculate tax based on” -> “Shop base address“). In this case, when a guest customer enters the checkout, tax will be calculated based on the store address.

The problem is that this option is unusual – businesses require the “Calculate tax based on” -> “Customer billing address” option in most cases.

So, today, we will be setting the default tax location when “Customer billing address” has been chosen AND the customer is either logged out (so, no billing address is set) or logged in but have no saved address (for example, a brand new customer). Enjoy!

It’s unusual to pick the “Shop base address” option for establishing the tax amounts. The snippet below will define a default tax location when “Customer billing address” is chosen instead and the customer has no billing address yet.

PHP Snippet: Set Customer Default Billing Country for Tax Calculations @ WooCommerce Checkout

/**
 * @snippet       Set Customer Default Tax Location
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 8
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'woocommerce_get_tax_location', 'bbloomer_customer_default_tax_location', 9999, 3 );

function bbloomer_customer_default_tax_location( $location, $tax_class, $customer ) {
    if ( $customer && ! $customer->get_billing_country() ) {
        return array( 'US', '', '', '' );
    }
    return $location;
}

Note: you can even set the default state, postcode and city by using the 3 array values after the country code e.g. ( ‘US’, ‘CA’, ‘90210’, ‘Beverly Hills’ )

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

2 thoughts on “WooCommerce: Set Customer Default Tax Location

  1. Muchas gracias 😀

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Your email address will not be published. Required fields are marked *