The code in this article is considered a customisation. As such, it's outside the scope of our support service. Should you need assistance implementing the code, please feel free to contact us to request a consultation.  


The Aelia Tax Display by Country plugin offers an option to keep product prices fixed, inclusive of tax, no matter what tax rate applies to them. For example, a product prices 100 EUR including tax will cost exactly 100 EUR to any customer, whether the VAT is 19%, 20%, 24%, or any other rate. This also applies when the VAT rate is zero. In this case. the price will simply become 100 EUR, without VAT. 


This behaviour is by design. The "fixed prices" feature is meant to always keep the prices fixed, for all customers, to ensure a consistent result. Due to that, when the feature is enabled, every customer always pays the same amount, whether VAT applies or not to their order.


If you need to enable the "fixed price" option only in specific cases, you can do so by implementing a filter for hook wc_aelia_tdbc_keep_prices_fixed. Below you can find an example of such a filter.


1. How to enable the "fixed price" option only for specific countries

The following snippet shows an example of how to enable the "fixed prices" option only for specific countries.

/**
 * This filter activates the "fixed prices" option only when the following conditions
 * are satisfied:
 * - The "prices fixed" is enabled.
 * - Customer's country belongs to a specific set of countries.
 * 
 * @param bool $enable_keep_prices_fixed
 * @return bool
 */
add_filter('wc_aelia_tdbc_keep_prices_fixed', function($enable_keep_prices_fixed): bool {
  // If the "fixed prices" option is enabled by default, don't do anything and leave it enabled
  if(!$enable_keep_prices_fixed) {
      // Fetch customer's country. The Tax Display by Country plugin stores it in a cookie
      $customer_country = $_COOKIE['aelia_customer_country'] ?? '';

      // Enable the "fixed prices" feature only if the country is one of the EU countries
      $enable_keep_prices_fixed = in_array($customer_country, [
        'FR', 
        'DE', 
        // Other EU countries...
      ]); 
  }
  return $enable_keep_prices_fixed;
});
This example uses customer's country as the criteria to determine if the "fixed prices" feature should be enabled.  This can be a quick way to keep prices fixed only for countries that actually pay VAT, while allowing WooCommerce to reduce the prices for countries to which VAT doesn't apply. Finding the tax rate that applies to the customer can be significantly more complex, as that information might not be available until after the totals have been calculated, and the "fixed prices" feature has been triggered.


Important

When using this code snippet, the "fixed prices" option, located at WooCommerce > Tax Display by Country > Tax Calculation must be disabled. If it's enabled, the code snippet will have no effect, and the option will be enabled for all countries.


2. Contact us if you have any questions

As indicated at the top of the article, all the code examples are provided on an "as is" basis, and they fall outside the scope of our support service. Although we won't be able to implement them for you, nor provide a guarantee that they will work, we will be happy to answer any questions you might have. You can contact us, and we will get back to you as soon as possible.


You can purchase the Aelia Tax Display by Country from our online shop.