Automattic / woocommerce-services

WooCommerce Services is a feature plugin that integrates hosted services into WooCommerce (3.0+), and currently includes automated tax rates and the ability to purchase and print USPS shipping labels.
GNU General Public License v2.0
107 stars 20 forks source link

When a non-taxable item is in the cart first, added taxable items are not taxed. #2537

Closed darcie closed 2 years ago

darcie commented 2 years ago

Related to #2514 likely.

Steps to Reproduce:

  1. Create a product that is not taxable and a product that is taxable
  2. Add the non-taxable item to the cart
  3. Add the taxable item to the cart
  4. Use an address that falls within the tax nexus
  5. The total tax is zero
  6. An error is logged Error retrieving the tax rates. Received (406): {"status":"406","error":"Not Acceptable","detail":"line_items is invalid"} (WCS Tax)
  7. A rate is added to Standard Rates for the 0.00% tax rate for the postal code used.

I can reproduce this in WooCommerce Shipping & Tax 1.25.23 and 1.25.22, it does not happen in 1.25.21. Due to this, I believe it is related to Pull #2516.

Screenshots:

Markup 2022-03-16 at 09 49 35 Markup 2022-03-16 at 09 50 01

Logs:

When no rate is returned:

03-16-2022 @ 09:43:00 - :::: TaxJar Plugin requested :::: (WCS Tax)
03-16-2022 @ 09:43:00 - :::: TaxJar API called :::: (WCS Tax)
03-16-2022 @ 09:43:00 - Requesting: taxjar/v2/taxes - {"from_country":"US","from_state":"CA","from_zip":"90210","from_city":"Beverly Hills","from_street":"123 Woo Way","to_country":"US","to_state":"CA","to_zip":"90210","to_city":false,"to_street":false,"shipping":"5","plugin":"woo","line_items":{"1":{"id":"41-3416a75f4cea9109507cacd8e2f2aefc","quantity":1,"product_tax_code":"","unit_price":"18","discount":"0"}}} (WCS Tax)
03-16-2022 @ 09:43:01 - Error retrieving the tax rates. Received (406): {"status":"406","error":"Not Acceptable","detail":"line_items is invalid"} (WCS Tax)
03-16-2022 @ 09:43:01 - Received: none. (WCS Tax)

Line items when the rate is successfully returned:

"line_items":[{"id":"41-3416a75f4cea9109507cacd8e2f2aefc","quantity":1,"product_tax_code":"","unit_price":"18","discount":"0"}]}

Reported in 4857330-zen and 4803765-zen

hmadisonturner commented 2 years ago

This is due to the array_filter() call in #2516 returning a sparse array, which is then encoded as an object by wp_json_encode( $body ). Wrapping the array_filter() call in array_values() fixes it, but it feels gross.

darcie commented 2 years ago

Another example in 4863532-zen

nawaz0705 commented 2 years ago

Reported in 4876335 - Zen