• Resolved audat

    (@audat)


    Hello,

    i need to exclude some products from tax exemption. I read the following article and don’t understand what’s meant with “the EU VAT Assistant doesn’t affect VAT calculation.”:
    https://wordpress.org/support/topic/how-to-exclude-vat-class/

    As far as i can see, if a customer enters a valid VAT and is from another EU-Country, the tax is not collected.

    I want to exclude some products from that behaviour. They should be taxed under all circumstances with the shop country local VAT.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Diego

    (@daigo75)

    The note in the post you found, in relation to the VAT calculation, means that the EU VAT Assistant is not taking part into the calculation itself. When a valid EU VAT number is entered, the EU VAT Assistant sets a “tax exemption” attribute against the customer session. WooCommerce then reads that attribute and decides what to do with it. In normal circumstances, the whole tax calculation is skipped, therefore no tax is applied, to any element of the order. This is by design in both WooCommerce and the EU VAT Assistant. The exemption can only be global, not product specific.

    If you want to apply a tax exemption just to some products, you will have to write a customisation, as follows:
    1. Write a filter for hook wc_aelia_eu_vat_assistant_customer_vat_exemption. When the exemption is being applied, keep track of that information (you will need it in step #2), then set it to false.

    Filter template

    add_filter('wc_aelia_eu_vat_assistant_customer_vat_exemption', function($customer_vat_exemption, $vat_country, $vat_number) {
      if($customer_vat_exemption) {
        // Keep track of this information, e.g. by storing it into a variable
      }
      // Always return false, as we don't want to use the global exemption
      return false;
    }, 10, 3);

    2. Write a filter for hooks woocommerce_product_get_tax_class and woocommerce_product_variation_get_tax_class. In these filters, check if an exemption is supposed to be applied (from #1). If it is, set the tax class to a zero rated one (e.g. “Zero Rate”).

    Filter template

    function maybe_set_zero_rate_tax_class($tax_class, $product) {
      // Set the tax rate to "Zero Rate" when the exemption flag is set
      // and the product is supposed to be exempt from tax. You could
      // use the product IDs, their category, or their original tax class, 
      // which is passed as a parameter, to determine if the product can be 
      // made exempt
      if(<YOUR GLOBAL VARIABLE IS SET AND THE PRODUCT SHOULD BE MADE EXEMPT>) {
        $tax_class = 'Zero Rate';
      }
      return $tax_class;
    }
    add_filter('woocommerce_product_get_tax_class', 'maybe_set_zero_rate_tax_class', 1, 2);
    add_filter('woocommerce_product_variation_get_tax_class', 'maybe_set_zero_rate_tax_class', 1, 2);

    The above will remove the “global exemption” set by the EU VAT Assistant, making sure that the taxes are always calculated, but with the “zero rate” applied to the products. This should keep the prices unchanged, like you indicated.

    Important
    The above information is provided as a suggestion, without guarantees. The logic I described will have to be completed with the necessary elements (tracking of the exemption, checking the product to see if it should be exempt) before it can be used on a site. You can pass this information to your developer, who can add the missing parts to the code.

    Please also note that customisations, like the one just described, are outside the scope of our support service. Should you need assistance implementing it, please feel free to contact us to schedule a consultation.

    Thread Starter audat

    (@audat)

    Thank you! I use if( is_product_category( 'category-slug' ) ) { to set excluded products.

    for tax class $tax_class = 'tax-class-slug';

    Now the exemption is set for the complete order, not for the specific product.

    Plugin Author Diego

    (@daigo75)

    Unfortunately, we can’t review or fix custom code, but if you’re trying to check if a product belongs to a category then the check is incorrect. Function is_product_category() indicates if you’re viewing a category, not if the product belongs to it. The following article might be of help to implement the correct check: https://rudrastyh.com/woocommerce/if-product-in-category.html

    Thread Starter audat

    (@audat)

    Ok, thank you. Yes, i would like to check by category, but the function doesn’t work.

    I’m not sure if i understood. Does that mean no, it can’t be per product? When a valid EU VAT number is entered, the EU VAT Assistant sets a “tax exemption” attribute against the customer session.

    Plugin Author Diego

    (@daigo75)

    That’s correct. The VAT exemption is set against the customer session, and WooCommerce applies it against the whole order. That’s by design, it’s just how WooCommerce works.

    Due to that, if you need a “partial exemption”, instead of setting the exemption against the customer you can simple apply “zero rate” to specific products, as described earlier.

    Thread Starter audat

    (@audat)

    Ok, thanks. Unfortunately, i can’t get the function to work. Can you give me an example on how to check for tax_class here? <YOUR GLOBAL VARIABLE IS SET AND THE PRODUCT SHOULD BE MADE EXEMPT>

    Plugin Author Diego

    (@daigo75)

    The tax class is passed as a parameter to the filter (see function maybe_set_zero_rate_tax_class($tax_class, $product). You can just compare $tax_class with your target value and base your custom logic on that. You will just have to remember to set the correct tax class against the appropriate products.

    For example, you could do the following:
    1. Create a tax class called “Always taxable” at WooCommerce > Settings > Tax
    2. Assign the new tax class to products that must never be exempt from tax (at Edit Product > Product data > General).
    3. Implement your check as if($tax_class !== 'Always taxable'), to set the zero rate against the not “always taxable” products.

    That’s one of the ways to implement the custom logic.

    Thread Starter audat

    (@audat)

    Thank you for that. But i still don’t understand how to put it together to work with the plugin.

    Plugin Author Diego

    (@daigo75)

    To put everything together, you will have to add the two code snippets I sent you to your theme’s functions.php file, then implement the code to keep track of the exemption that the EU VAT Assistant (step #1) and change the tax class of the correct products (step #2).

    This customisation should be straightforward, but some knowledge of WooCommerce and WordPress development is required. If you have a developer who helps you with your site, he should be able to fill the gaps and complete the implementation.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Exclude Product from Tax exemption’ is closed to new replies.