-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Fix: wc_get_price_excluding_tax when an order with no customer is passed #31015
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
Fix: wc_get_price_excluding_tax when an order with no customer is passed #31015
Conversation
PR #30692 modified 'wc_get_price_excluding_tax' so that if an order is passed its customer will be passed to WC_Tax::get_rates in order to use the proper location for the taxes to be discounted. The problem is that when the order has no customer (it's "Guest") an invalid customer (id=0) is passed, which has no location, and thus no taxes are deducted whatsoever. The fix consists of checking if the customer id from the order is 0, and in that case no customer is passed to WC_Tax::get_rates, thus the shop location is used for the taxes.
…g_tax Modify wc_get_price_excluding_tax so that when there's no user available from a passed order and the 'woocommerce_adjust_non_base_location_prices' filter returns false, the shop base location is used for the tax calculation instead of the location of the currently logged in user.
peterfabian
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note for future myself:
woocommerce_adjust_non_base_location_pricesfilter set to false means that all customers irrespective of their billing/shipping country should pay the same price incl tax.
Overall, I think it works fine, although the UX is not super nice since the merchant needs to save/update orders in between.
Great job with those tests, I think it should cover all the eventualities.
|
Hi @Konamiman, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
|
Merged into |
|
Cherry-picked into |
All Submissions:
Changes proposed in this Pull Request:
#30692 introduced a change in the
wc_get_price_excluding_taxfunction: if thewoocommerce_adjust_non_base_location_pricesis set to returnfalse, the function is supposed to take the location of the customer from the order for the taxes calculation, but wasn't doing so when the order was being created directly from the admin area because no customer was being passed toWC_Tax::get_rates; thus, the location from the currently logged in user was being used instead. With the fix from that PR, the order was being passed towoocommerce_adjust_non_base_location_pricesand its customer location was used for the taxes calculation.The problem is that a newly created order with no customer whatsowever has actually a "null customer" with a zero customer id. The code was taking that to calculate taxes, which resulted in no taxes being deducted; adding a new line item would result in the full product price being added, with taxes; and pressing "Recalculate" would add the taxes again.
This PR fixes that: if an order is passed to
woocommerce_adjust_non_base_location_prices, a check is done for the cusomer id, and if it's 0 then the shop base location is used for the tax calculation as a fallback.Closes #31013.
How to test the changes in this Pull Request:
Note: These instructions are an extended version of the ones for #30692.
add_filter( 'woocommerce_adjust_non_base_location_prices', '__return_false' );Other information:
Changelog entry
N/A (it's a fix for #30692, which was included in 5.9 beta)
FOR PR REVIEWER ONLY: