Setting a post code for correct taxation with the Local Pickup setting

If you're selling to people in different parts of the country or the world, you normally base the tax on the location of the customer. For that reason, you don't normally have to set your own zip code or city. But if you sell to people outside your city most of the time, but also have the Local Pickup shipping method selected, then you'll need to set your zip code and city.

How to do it…

This is an edge case, so there isn't any way to do this in the admin. You have to do this with some custom code, using the following steps:

  1. Open your theme's functions.php file, located under wp-content/themes/your-theme-name/, or create a custom WooCommerce plugin.
  2. At the bottom of the file, enter the following lines of code to set your city:
    add_filter( 'woocommerce_countries_base_city' , 'woocommerce_cookbook_countries_base_city' ); 
    function 'woocommerce_cookbook_countries_base_city'() { 
        // Replace with your store town/city 
        return 'Townland'; 
    }
  3. In this snippet, replace Townland with the name of your city.
  4. And, below that, add the following lines of code to set your zipcode:
    add_filter( 'woocommerce_countries_base_postcode' , 'woocommerce_cookbook_countries_base_postcode' ); 
    function woocommerce_cookbook_countries_base_postcode() { 
        // Replace with your store postcode / zipcode 
        return '45040'; 
    }
  5. Replace 45040 with your actual zip code.

Now that you've set your city and zip code, the Local Pickup method will use those for taxation. You still need to set the rates. See the Manually entering tax rates recipe we've covered earlier.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset