Skip to content

Conversation

@allie500
Copy link
Contributor

@allie500 allie500 commented Oct 30, 2025

Description

This change is being added to give us better visibility into the issue reported in WOOSHIP-1686. Many merchants located in US states other than California have reported intermittent issues where California customers are being charged sales tax for orders from their stores.

This PR adds a method that logs when this happens and indicates if the response came directly from TaxJar or if it was a cached response. The method is only called if the store's address state is not California.

Related issue(s)

Fixes WOOSHIP-1713

Testing

To test the logging method, we need to apply a patch file to remove the check for the store address in California so that the logging check method runs and the correct (taxable) responses are returned from TaxJar and the cache.

  • Apply this patch: woo-services-pr2893.patch
  • Set your store address to the A8C corporate address:
    • 60 29th Street #343
    • San Francisco, CA 94110
  • Go to the frontend of your site and add an item to your cart.
  • Go to the checkout page and enter the customer info, using a California address.
  • Check the logs for the following string: Incorrect California tax nexus detected in TaxJar API response. (WCS Tax)
  • Now visit the shop or homepage of your local site, then go back to the checkout.
  • Check the logs for the following string: Incorrect California tax nexus detected in cached response. (WCS Tax)

Post testing clean up:

  • If desired, change the store address to whatever it was before.
  • Go to WooCommerce > Settings > Tax > Standard rates and delete the CA related tax rates.
  • Access your local env database via phpMyAdmin and delete all TaxJar related cache transients:
SELECT * FROM `wp_options` WHERE `option_name` LIKE '%tj_tax_%';

Example Data

Non-taxable out of state response body from TaxJar API:
[31-Oct-2025 13:25:12 UTC] stdClass Object
(
    [tax] => stdClass Object
        (
            [amount_to_collect] => 0
            [freight_taxable] => 
            [has_nexus] => 
            [order_total_amount] => 43.95
            [rate] => 0
            [shipping] => 9.95
            [tax_source] => 
            [taxable_amount] => 0
        )

)
 (WCS Tax)
Cached response body for taxable order:
[body] => {"tax":{"freight_taxable":true,"tax_source":"destination","rate":0.0675,"jurisdictions":{"state":"NC","city":"CLAYTON","country":"US","county":"JOHNSTON COUNTY"},"shipping":9.95,"taxable_amount":27.95,"amount_to_collect":1.89,"breakdown":{"shipping":{"tax_collectable":0.67,"taxable_amount":9.95,"combined_tax_rate":0.0675,"state_taxable_amount":9.95,"county_taxable_amount":9.95,"city_taxable_amount":0.0,"city_tax_rate":0.0,"county_tax_rate":0.02,"special_tax_rate":0.0,"special_district_amount":0.0,"special_taxable_amount":0.0,"city_amount":0.0,"county_amount":0.2,"state_amount":0.47,"state_sales_tax_rate":0.0475},"tax_collectable":1.89,"taxable_amount":27.95,"line_items":[{"id":"32-6364d3f0f495b6ab9dcf8d3b5c6e0b01","tax_collectable":1.22,"taxable_amount":18.0,"combined_tax_rate":0.0675,"state_taxable_amount":18.0,"county_taxable_amount":18.0,"city_taxable_amount":0.0,"special_district_taxable_amount":0.0,"city_tax_rate":0.0,"county_tax_rate":0.02,"special_tax_rate":0.0,"special_district_amount":0.0,"city_amount":0.0,"county_amount":0.36,"state_amount":0.86,"state_sales_tax_rate":0.0475}],"combined_tax_rate":0.0675,"state_taxable_amount":27.95,"state_tax_collectable":1.33,"county_taxable_amount":27.95,"county_tax_collectable":0.56,"city_taxable_amount":0.0,"city_tax_collectable":0.0,"special_district_taxable_amount":0.0,"special_district_tax_collectable":0.0,"city_tax_rate":0.0,"county_tax_rate":0.02,"special_tax_rate":0.0,"state_tax_rate":0.0475},"has_nexus":true,"order_total_amount":27.95}}
TaxJar API response body for taxable order:
[30-Oct-2025 18:08:55 UTC] TaxJar response body: stdClass Object
(
    [tax] => stdClass Object
        (
            [freight_taxable] => 1
            [tax_source] => destination
            [rate] => 0.0675
            [jurisdictions] => stdClass Object
                (
                    [state] => NC
                    [city] => CLAYTON
                    [country] => US
                    [county] => JOHNSTON COUNTY
                )

            [shipping] => 9.95
            [taxable_amount] => 27.95
            [amount_to_collect] => 1.89
            [breakdown] => stdClass Object
                (
                    [shipping] => stdClass Object
                        (
                            [tax_collectable] => 0.67
                            [taxable_amount] => 9.95
                            [combined_tax_rate] => 0.0675
                            [state_taxable_amount] => 9.95
                            [county_taxable_amount] => 9.95
                            [city_taxable_amount] => 0
                            [city_tax_rate] => 0
                            [county_tax_rate] => 0.02
                            [special_tax_rate] => 0
                            [special_district_amount] => 0
                            [special_taxable_amount] => 0
                            [city_amount] => 0
                            [county_amount] => 0.2
                            [state_amount] => 0.47
                            [state_sales_tax_rate] => 0.0475
                        )

                    [tax_collectable] => 1.89
                    [taxable_amount] => 27.95
                    [line_items] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [id] => 32-6364d3f0f495b6ab9dcf8d3b5c6e0b01
                                    [tax_collectable] => 1.22
                                    [taxable_amount] => 18
                                    [combined_tax_rate] => 0.0675
                                    [state_taxable_amount] => 18
                                    [county_taxable_amount] => 18
                                    [city_taxable_amount] => 0
                                    [special_district_taxable_amount] => 0
                                    [city_tax_rate] => 0
                                    [county_tax_rate] => 0.02
                                    [special_tax_rate] => 0
                                    [special_district_amount] => 0
                                    [city_amount] => 0
                                    [county_amount] => 0.36
                                    [state_amount] => 0.86
                                    [state_sales_tax_rate] => 0.0475
                                )

                        )

                    [combined_tax_rate] => 0.0675
                    [state_taxable_amount] => 27.95
                    [state_tax_collectable] => 1.33
                    [county_taxable_amount] => 27.95
                    [county_tax_collectable] => 0.56
                    [city_taxable_amount] => 0
                    [city_tax_collectable] => 0
                    [special_district_taxable_amount] => 0
                    [special_district_tax_collectable] => 0
                    [city_tax_rate] => 0
                    [county_tax_rate] => 0.02
                    [special_tax_rate] => 0
                    [state_tax_rate] => 0.0475
                )

            [has_nexus] => 1
            [order_total_amount] => 27.95
        )

)
 (WCS Tax)

Steps to reproduce & screenshots/GIFs

The bug that this PR seeks to log is difficult to reproduce as it is intermittent.

Checklist

  • unit tests
  • changelog.txt entry added
  • readme.txt entry added

@allie500 allie500 self-assigned this Oct 30, 2025
@allie500 allie500 requested a review from samnajian October 31, 2025 15:45
@allie500 allie500 marked this pull request as ready for review October 31, 2025 15:45
Copy link
Contributor

@samnajian samnajian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,
Left some suggestions.

$response = $response ? $response : get_transient( $cache_key );
if ( $response && 'CA' !== $from_state ) {
// If $from_state is not California, we need to check for incorrect California tax nexus.
$this->check_for_incorrect_california_tax_nexus( $response['body'], true );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest wrapping the calls to this function in try/catch block, so that adding extra logging can't break the main flow of the application.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this suggestion. I've added it in 3fe7a48.

$has_nexus = $response_body->tax->has_nexus;

if ( 'CA' === $to_state && 'US' === $to_country && true === $has_nexus ) {
$this->_log( 'Incorrect California tax nexus detected ' . $log_suffix );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding the following to the log?

sprintf( 
				'Incorrect California tax nexus detected %s (from_state: %s, to_state: %s, to_country: %s, has_nexus: %s)',
				$log_suffix,
				$from_state ?: 'unknown',
				$to_state,
				$to_country,
				$has_nexus ? 'true' : 'false'
			)

This adds more information to the log and can help with the debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I've added it in 3fe7a48. I re-tested by applying the patch and setting my store address to California to trigger the logging and it worked as expected. Logs and patch below.

[05-Nov-2025 14:25:56 UTC] Incorrect California tax nexus detected in TaxJar API response. (from_state: CA, to_state: CA, to_country: US, has_nexus: true). (WCS Tax)
[05-Nov-2025 14:26:58 UTC] Incorrect California tax nexus detected in cached response. (from_state: CA, to_state: CA, to_country: US, has_nexus: true). (WCS Tax)
diff --git a/classes/class-wc-connect-taxjar-integration.php b/classes/class-wc-connect-taxjar-integration.php
index 7a4879e4..8f0d7929 100644
--- a/classes/class-wc-connect-taxjar-integration.php
+++ b/classes/class-wc-connect-taxjar-integration.php
@@ -1442,7 +1442,7 @@ class WC_Connect_TaxJar_Integration {
 			$response            = get_transient( $zip_state_cache_key );
 		}
 		$response = $response ? $response : get_transient( $cache_key );
-		if ( $response && 'CA' !== $from_state ) {
+		if ( $response ) {
 			// If $from_state is not California, we need to check for incorrect California tax nexus.
 			try {
 				$this->check_for_incorrect_california_tax_nexus( $response['body'], true, $from_state );
@@ -1460,13 +1460,10 @@ class WC_Connect_TaxJar_Integration {
 			$response      = $this->smartcalcs_request( $json );
 			$response_code = wp_remote_retrieve_response_code( $response );
 			$body          = json_decode( wp_remote_retrieve_body( $response ) );
-			if ( 'CA' !== $from_state ) {
-				// If $from_state is not California, we need to check for incorrect California tax nexus.
-				try {
-					$this->check_for_incorrect_california_tax_nexus( $body, false, $from_state );
-				} catch ( Exception $e ) {
-					$this->_log( 'Error checking for incorrect California tax nexus: ' . $e->getMessage() );
-				}
+			try {
+				$this->check_for_incorrect_california_tax_nexus( $body, false, $from_state );
+			} catch ( Exception $e ) {
+				$this->_log( 'Error checking for incorrect California tax nexus: ' . $e->getMessage() );
 			}
 			$is_zip_to_state_mismatch = (
 				isset( $body->detail )

@samnajian
Copy link
Contributor

@allie500 the fix added here and in this commit will fix the failing tests in this PR as well.

@allie500 allie500 merged commit ef86dc5 into trunk Nov 5, 2025
9 checks passed
@allie500 allie500 deleted the add/WOOSHIP-1713-log-incorrect-california-tax-nexus branch November 5, 2025 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants