How To Make Geo Location Specific WooCommerce Customizations


Personalized messages tend to perform well and also manages to make more conversions than the generic ones. Geo targeted WooCommerce customizations not only helps you to show targeted messages with these customizations you also can make the taxes and rates calculated for that region. So managing your payments and shipments become simpler.

[the_ad id=’6609′]

Detecting User’s Geolocation & Personalized Message

This is the key phrase and the first step in identifying your user. Once you did this clearly then you can do any other related customizations easily. This code snippet acts based on the user IP address.

Note that before using this code, make sure you have enabled Geolocation in WooCommerce. Using the WC_Geolocation::geolocate_ip() code you can easily fetch the user’s geolocation, from here you can add switch condition to personalize your message.

[code language=”php”]
function wpts_use_geolocated_user_country(){

// Enable Geolocation @ Woo Settings

$location = WC_Geolocation::geolocate_ip();
$country = $location[‘country’];

// Let us make country specific greetings

switch ($country) {
case “IE”:
$hello = “Howya!”;
case “IN”:
$hello = “Namaste!”;
$hello = “Hello!”;

echo $hello;

add_action( ‘_______’, ‘wpts_use_geolocated_user_country’ );

You can paste this PHP code in your child theme’s function.php file right below the before the finishing line “?>”. After detecting your user’s location this code welcomes them with the word you mentioned for that particular country. The output of the above code will be looking like the below image.


Sales By State

Being an e-commerce shop owners we have customers all over the country. At the fiscal year ending, we have to make our data country specific to make the taxation work properly and less cluttered. By default, WooCommerce won’t give you a sales report for the specific region, but by making minor code adjustments, you can get the desired result you want.

[code language=”php”]
// 1. Creating Sales by State Tab

add_filter( ‘woocommerce_admin_reports’, ‘wpts_admin_add_report_orders_tab’ );

function wpts_admin_add_report_orders_tab( $reports ) {

$array = array(
‘sales_by_state’ => array(
‘title’ => ‘Sales by state’,
‘description’ => ”,
‘hide_title’ => 1,
‘callback’ => ‘wpts_yearly_sales_by_state’

$reports[‘orders’][‘reports’] = array_merge($reports[‘orders’][‘reports’],$array);

return $reports;

// ———————–
// 2. Calculate sales by state

function wpts_yearly_sales_by_state() {

$year = 2017; // change this if needed
$total_ca = $total_wa = 0; // add states if needed

$args = [
‘post_type’ => ‘shop_order’,
‘posts_per_page’ => ‘-1’,
‘year’ => $year,
‘post_status’ => [‘wc-completed’]
$my_query = new WP_Query($args);
$orders = $my_query->posts;

foreach ($orders as $order => $value) {

$order_id = $value->ID;
$order = wc_get_order($order_id);
$order_data = $order->get_data();

if ( $order_data[‘billing’][‘country’] === ‘US’ ) {
if ( $order_data[‘billing’][‘state’] === ‘CA’ ) $total_ca += $order->get_total();
if ( $order_data[‘billing’][‘state’] === ‘WA’ ) $total_wa += $order->get_total();


echo “
<h3>Sales by State for Year ” . $year . “</h3>

echo “CA: ” . wc_price($total_ca) . “</br>”;
echo “WA: ” . wc_price($total_wa) . “</br>”;


How it works:

From the list of purchases made, this code snippet will filter the purchases fall within the category of states you mentioned. This can be visualized within your dashboard. All you have to do is to go to the dashboard and select WooCommerce >> Reports>> Orders tab, there you will find an option sales by state, from there you can see the sales for a particular state.


[the_ad id=’6614′]

Showing Tax To Users Based on Geolocation

For this, there are two options. One is a default option in the WooCommerce, which you have to configure and activate it manually. If you need more precise result with more advanced features for you to manage easily then you have to go for a WooCommerce add-on.

Tweaking Default Settings

As said before in the Detecting user Geolocation, you have to switch on the customer location tracking. For that go to the WooCommerce general settings, under the Default customer location select the Geolocate option.


After enabling the geolocation you can see a tick box showing “Enable tax and tax calculation”. Make sure you check that box. After that, your general settings option will have a separate tab for tax as shown in the image below.


[the_ad id=’6614′]

Plugins For Geolocation Based Tax Calculation

Adding tax to the WooCommerce code is not an easy job as the tip we gave you in the WooCommerce discount sale customizations. This includes lots of backend functionality and takes a lot of time. So if you are a general user expecting advanced tax option, it is better to go for a WooCommerce extension.


Avatax is the best solution for the tax calculation. Even WooCommerce itself provides a free extension to integrate Avatax. But the Avatax is a premium service, you have to buy it separately and can add it easily to your WordPress website easily via the WooCommerce add-on.

WooCommerce AvaTax allows you to charge appropriate tax automatically and track tax records for your WooCommerce transactions, and can also enable AvaTax address validation for your customers.


Aelia is also a premium plugin. This plugin allows the user to select the country and the currency they prefer. You have the option to show the price with and without tax. If you prefer to show product price and the tax separately, you have options for that also. Since it is a premium plugin you have multiple options and more useful features.


  • Fully compatible with our WooCommerce Currency Switcher plugin
  • Allows displaying prices with or without tax, depending on visitors’ country.
  • Automatically detects visitors’ country, with price accordingly displayed with/without taxes.
  • Allows keeping product prices fixed, including taxes, independently from what tax rate applies to customers (available in v1.7.0.150109 and later).
  • Pre-selects the checkout country automatically.
  • Includes a widget to allow your visitors to choose their billing country before they reach the checkout.
  • Allows specifying a price suffix for each tax display rule.
  • Allows visitors to declare themselves exempt from tax and always see tax-exclusive prices.

EU Vat Compliance

EU Vat Compliance is a free plugin that you can use only for calculating tax in the European countries. If you are selling products only in the European region, then this plugin will help you.


  • Identify your customers’ locations
  • Full information that was used to calculate VAT and customer location is displayed in the WooCommerce order screen in the back-end.
  • Currency conversion supported
  • Can maintain VAT rates for each country separately
  • Forbid EU sales if any goods have VAT chargeable
  • Can Distinguish VAT from other taxes

Wrap Up

These are some of the Geo targeted WooCommerce customizations you can do to make a more personalized online store. Since all the customizations aren’t that simple that an end user can do, we have mentioned plugins to make it easier for you. To get more WooCommerce related tips and tricks please subscribe to our newsletter. Happy Website!!

[the_ad id=’6616′]

Leave a Reply

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