How can I provide goods from multiple countries and apply base-country rules?

Some complicated stores sell goods from multiple countries, on a single WooCommerce installation. WooCommerce only has a single “store base country” setting. This is a problem for such stores, because under VAT rules, goods provided within the country of supply (i.e. where the customer’s taxation country is the same as the customer of supply) are treated differently – specifically, VAT is always charged in-country. Our plugin has some “base country” settings to handle in-country supply, but if there is more than one base country, then the default setup cannot handle it.

(N.B. If your question is about something else, then you should stop reading – this FAQ deals with the scenario just-described and no others).

In this situation, it is possible to make the plugin deal with your setup, by doing the following:

  1. Put goods that are under separate tax regimes (which includes being supplied from separate countries) into their own tax class. i.e. Goods supplied from different countries should not be in the same tax class. This is something you ought to be doing anyway. But when you do so, you should include the country code in the tax class name, surrounded by two underscores, e.g. _de_ for Germany, _nl_ for the Netherlands. (Whether upper-case or lower-case does not matter). So, an example tax class would be Physical_Goods_de_Class. If you prefer not to do this, then you must instead list all your tax classes (in WooCommerce’s internal text format) in the code that is used below at the last step.
  2. In WooCommerce -> Settings -> Taxes, create a tax class with a name like “Unused Tax Class – Do Not Delete”. You do not need to create a tax table for this tax class; it is unused. Its sole reason for existing is to cause certain code paths to be chosen in order to enable the solution. If you delete it, the solution may stop working, so do not delete it.
  3. In our VAT plugin settings, make sure that any tax classes that you wish to be exempt upon supply of a valid VAT number are selected in the relevant setting for exemptions, but that the unused tax class above is not selected.
  4. In our VAT plugin settings, make sure that users in your base country are allowed to enter a VAT number, and that they are set to be eligible to be VAT exempt.
  5. Finally, add the “must-use plugin” below to your WordPress install. This means that you should create the folder wp-content/mu-plugins if it does not already exist, and must save the code below as a .php file in that folder, e.g. as wp-content/mu-plugins/multiple-vat-base-countries.php . You must edit the line where it says “On this line, list the country codes for which you have places of supply” to list your relevant country codes, or instead edit the list of tax classes shown (either way works):
    add_filter('wc_vat_woocommerce_product_get_tax_class_zero_rate_class', function($new_class, $original_class, $product, $zero_rate_reason) {
      $zero_rate_class = apply_filters('wc_vat_exempt_zero_rate_tax_class', 'zero-rate', $original_class, $product);
      // We only want to get involve if a decision as made to zero-rate due to the product being in a specified tax class
      if ($new_class !== $zero_rate_class || $original_class === $zero_rate_class || 'in_partially_exempt_class' !== $zero_rate_reason) return $new_class;
      // Define the country from which goods in specific tax classes are being sold, if your class names do not follow the convention in the instructions above
      $base_country_for_tax_class = array(
        'example_class' => 'DE',
        'another_example_class' => 'NL',
      // Only get involved if the product tax class is one of those we are interested in, or follows the same patterns (to allow for future changes in tax class names)
      if (in_array($original_class, array_keys($base_country_for_tax_class))) {
         $product_sold_from = $base_country_for_tax_class[$original_class];
      // On the line below, list the country codes for which you have places of supply
      } elseif (preg_match('/_(de|nl|ca)_/i', $original_class, $matches)) {
        $product_sold_from = strtoupper($matches[1]);
      } else {
      $wc = WC();
      $wc_session = isset($wc->session) ? $wc->session : null;
      $tax_country = $wc_session ? $wc_session->get('vat_country_checkout') : '';
      if ('' == $tax_country || '??' == $tax_country || 'none' == $tax_country) $tax_country = $wc->customer->get_billing_country();
      if ($product_sold_from !== $tax_country) return $new_class;
      // Country is being sold from the base country for this product; reverse the zero-rating
      return $original_class;
    }, 10, 5);

    If you have done all that correctly, then you should now find that which country is counted as your “supply” country varies on a line-item-by-line-item basis for goods in different tax classes.

Posted in: WooCommerce EU/UK VAT Compliance