I am trying to add a form to my checkout page so when a user clicks the 'Tax Exempt' checkbox, a textbox will popup and ask the user what the Tax Exempt Id number is.
I got all of that working great, and I even added the update_totals_on_change
class to my form field so it will update the totals.
My next step was to add an action/filter on a method so when the update_totals_on_change
executes, I can set the tax to 0 and then it will finish calculating the total.
Does anyone know which functions I can hook on to?
Looking at the checkout.js
file in WooCommerce
, they set the action to woocommerce_update_order_review
for the ajax
operation.
I tried following that but soon got lost.
I was thinking I could add some post data by hooking in to woocommerce_checkout_update_order_review
and then hooking in to woocommerce_before_calculate_totals
to modify the tax stuff, but I have no idea what I need to modify.
Am I even on the right path?
Alright, I finally figured it out in case anyone is interested.
In my plugin, I made a form after the order notes by hooking in to this function: 'woocommerce_before_order_notes'
my 'taxexempt_before_order_notes' function contained:
Then the most important woocommerce function to hook was: 'woocommerce_checkout_update_order_review'
I simply parsed out the $post_data that is the serialized form data from the checkout.js file in woocommerce and checked if my part of the form was filled out correctly.
If it was, then I would set the tax exempt for the user.
The accepted solution didn't work for me, but I modified it to use the following:
The key here is understanding that any field with a name that starts with
shipping_method
is going to inherit this updating order functionality (which was the part that didn't work for me). I found this answer at http://www.affectivia.com/blog/have-a-checkbox-on-the-checkout-page-which-updates-the-order-totals/Since this answer still pops up on google, I thought I'd share that setting the customer as tax exempt only works during checkout, if you need to edit the order on the back-end after it is placed and use the "recalculate" button, the taxes will still appear. Fortunately there is a hook for this as well:
Because
$cart->remove_taxes();
is deprecated. This is what I used instead.I didn't have a form on the frontend, but have a user roll that is tax exempt. This was my solution.
Also worth noting that
set_is_vat_exempt(true)
also works in the US to set as tax exempt.After a long search I found that there is a method for the cart object called remove_taxes() . So, after setting a user meta for the tax exempt users, this cancels the tax totals.