Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transients Cache doesn't update upon user_exemption_type update. #243

Open
ghost-writer-727 opened this issue Apr 6, 2023 · 1 comment

Comments

@ghost-writer-727
Copy link

If a user builds a cart while is Non Exempt then realizes they should be exempt and calls my company to have it fixed, we can change them to a valid exempt type ('other'). However, the cart remains taxed as long as the address, products and quantities remain the same.

We have tried updating the quantities and then putting them back. We have tried clearing the cart, all cookies and all browser cache, then logging back in and when any previous combination of address, products and quanities return the previous tax calculation is also returned.

I believe the cleanest solution would be to include the user's tax status in the $request_body property of the Tax_Calculator class. This way when when the transient key is set, it is unique based on whether or not the user is exempt or not.

@ghost-writer-727
Copy link
Author

I actually see that the request body object already supports an exemption type. The issue is that there isn't one being passed to it. However, this hook makes it easy to force the exemption type. Here's my current solution that works well and still allows for caching.

function force_set_cart_exemption_type( $exemption_type, $cart ){
      if( $cart ){
	      if( $customer = $cart->get_customer() ){
		      if( $user_id = $customer->get_id() ){
			      $exemption_type = get_user_meta( $user_id, 'tax_exemption_type', true );
		      }
	      }
      }
      return $exemption_type;
}
add_filter( 'taxjar_cart_exemption_type', 'force_set_cart_exemption_type', 10, 2 );

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

No branches or pull requests

1 participant