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?
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_Cartadd_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_Cartadd_fee()method was not made for discounts.1) Reminder about
WC_Cartadd_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).