I am adding a WooCommerce cart fee like so :
add_action('woocommerce_cart_calculate_fees', function($cart) {
$cart->add_fee(__('Popust za vjernost'), -10, 0);
});
I thought adding a 0 as the third argument would set the tax to 0 but WooCommerce still adds tax to the fee.
How can I set the tax to 0?
2
Answers
To set the tax to 0 for a WooCommerce cart fee, you can use the fourth argument of the
add_fee
method to specify that tax should not be applied. Here’s how you can modify your code:By passing
false
as the third argument and an empty string''
as the fourth argument, you are indicating that no tax should be applied to the fee. This should prevent WooCommerce from adding tax to the fee.Overwriting cores files is not a solution, as it can affect other processes and you will lose your changes each time you will update WooCommerce.
Using
WC_Cart
add_fee()
method with a negative amount, is a tweak to add a discount. In that case, the "taxable" optional 3rd argument doesn’t work, and taxes are always applied. This has been reported to WooCommerce many times and the response was thatWC_Cart
add_fee()
method was not made for discounts.1) Reminder about
WC_Cart
add_fee()
method 4 available arguments:2) Make the "taxable" 3rd argument working with negative amounts:
The following code will enable "taxable" when using a negative amount, allowing to add a discount without taxes when the "taxable" argument is set to
false
:Code goes in functions.php file of your child theme (or in a plugin).
3) Testing using
Add_fee()
:Below, we add a discount without taxes using a negative amount:
This time it works, taxes are not applied and when order is submitted, same thing.
Code goes in functions.php file of your child theme (or in a plugin).