[WOOTAX-250] fix: implement itemized tax calculation for mixed carts services#2920
Open
ayushpahwa wants to merge 26 commits intotrunkfrom
Open
Conversation
06f31d6 to
7d85709
Compare
Contributor
|
@ayushpahwa numerous tests are failing, do you mind fixing them while I'm testsing? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Modify
calculate_totals()to support multiple tax locations in a single cart. This enables mixed carts containing both physical products (taxed at customer's shipping address) and services/bookings (taxed at store base address) by grouping items by theirtax_locationand making separate TaxJar API calls per group.Key changes:
group_items_by_location()— Groups line items by theirtax_locationkey (set by thewoocommerce_tax_line_item_locationfilter from #2917)calculate_taxes_by_location()— Loops over groups, makes separate API calls, merges resultsget_taxable_address()/get_address()— Extended with$location_typeparameter to resolve addresses per groupis_local_pickup()— Extracted fromget_taxable_address()for reuse; forces all items to'base'when local pickup is selectedoverride_item_tax_rates()— Ensures WooCommerce applies the correct per-item rates from TaxJar (not its native rate lookup)aggregate_tax_totals()— Combines duplicate tax labels from different locations into single display lines (e.g., two "County Tax" entries become one)calculate_tax()returns empty taxes instead offalse, allowing other groups to proceed. A safety net returnsfalseif all groups produce empty taxes.Related issue(s)
Fixes WOOTAX-250
Prerequisites
/wp-admin/admin.php?page=next-admin&p=%2Fwoocommerce%2Fsettings%2Ftaxes)/wp-admin/admin.php?page=next-admin&p=%2Fwoocommerce%2Fsettings%2Ftaxes%2Frates) — stale rates from previous sessions can cause incorrect taxesSetup
Check out the branch locally and on CIAB
Create the test mu-plugin in your CIAB container to simulate a mixed cart (forces every other cart item to use the store's base address for tax):
Replace
<CONTAINER_ID>with your WordPress container ID (docker ps).Test scenarios
Test 1: Cross-state — customer in a different US state
wp-content/debug.log— you should see:Test 2: In-state — customer in the same US state
Test 3: Single location cart (no regression)
docker exec <CONTAINER_ID> rm /var/www/html/wp-content/mu-plugins/wootax-250-test.php)Checklist
changelog.txtentry addedreadme.txtentry added