taxjar / taxjar-woocommerce-plugin

WooCommerce Sales Tax Plugin by TaxJar
http://www.taxjar.com/woocommerce-sales-tax-plugin/
GNU General Public License v2.0
28 stars 29 forks source link

Refactor Cart Tax Calculation #205

Closed dallendalton closed 2 years ago

dallendalton commented 2 years ago

Previously, the integration calculated tax in the cart by allowing WooCommerce to fully run through it's calculation process, then send an API request to TaxJar to get the correct tax amounts, create a tax rate in the WooCommerce tax table and finally re-trigger the hooks necessary for WooCommerce to completely run through its calculate totals processes this time using our inserted rates.

This approach was previously necessary but often created conflicts with other plugins that required special handling and logic.

This PR introduces a new approach. Now the integration runs on the woocommerce_after_calculate_totals. It performs an API request to TaxJar and then directly applies the tax to the applicable line items, fees, shipping, etc and recalculates the totals that have been altered. This new process no longer causes hooks to run multiple times which was the root cause of many issues.

Steps to Reproduce

  1. Do this
  2. And that
  3. Finally this

Expected Result

After applying the PR, this should happen.

Click-Test Versions

Specs Passing