1

I have a WooCommerce shop based in UK which sells internationally. I have set up different tax rates for different countries and integrated MaxMind IP Geolocation. The price with correct tax rate by country is displayed in the basket and checkout page before I enter the shipping address. However, the shop (and single product) page still shows the base country’s taxes (UK in my case). I have used the below code (edited from this trail [How to show correct tax on basket] (How to show correct tax on basket (BEFORE checkout)?) ), hoping that it would work also for the shop page (it doesn't in my case).

   add_filter( 'woocommerce_countries_base_country', 'get_user_geo_country', 1, 1);
              
    function get_user_geo_country(){
                $geo      = new WC_Geolocation();
                $user_ip  = $geo->get_ip_address();
                $user_geo = $geo->geolocate_ip( $user_ip );
                $country  = $user_geo['country']; // Get the country code
                return WC()->countries->countries[ $country ];
            }

Any guidance would be greatly appreciated (above code edited after further testing).

WooCommerce settings that I am using: Default customer Location: geolocate with cache support (I have tried also without cache support); Entered prices without taxes; Display prices in the shop, basket and checkout with taxes; Taxes calculated based on shipping address (I would like to keep this setting as is in case a customer is buying from a country but then ships to another). Thanks!

Manu
  • 21
  • 7
  • Does this answer your question? [Get the tax rate(s) from an order in WooCommerce 3](https://stackoverflow.com/questions/57861080/get-the-tax-rates-from-an-order-in-woocommerce-3) – Martin Zeitler Aug 20 '21 at 05:31
  • Hi Martin, I am afraid this doesn't solve my issue. I would like the tax code I set up for each country to be retrieved based on geo-located country (this may be different from the tax rate used for an order, which actually is based on shipping address) – Manu Aug 21 '21 at 05:46

1 Answers1

0

I think no need to code for this.

woocommerce also have this functionality, where you can define tax rate and shipping country wise.

Go to woocommerce -> settings -> Standard rates and define taxes

Reference URL : https://docs.woocommerce.com/document/setting-up-taxes-in-woocommerce/

Rajeev Singh
  • 1,724
  • 1
  • 6
  • 23