From 6e9c348cc40d792680f2ad85fd7d5d8d8bc6a19f Mon Sep 17 00:00:00 2001 From: Seghir Nadir Date: Mon, 27 Jun 2022 15:52:24 +0100 Subject: [PATCH] add custom local pick handling (https://github.com/woocommerce/woocommerce-blocks/pull/6631) This PR fixes an issue in which taxes are calculated against the user address for local pickups orders. A niche issue, but an important one. --- .../StoreApi/Utilities/OrderController.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/plugins/woocommerce-blocks/src/StoreApi/Utilities/OrderController.php b/plugins/woocommerce-blocks/src/StoreApi/Utilities/OrderController.php index 2549fcfb6f8..aa583c560d5 100644 --- a/plugins/woocommerce-blocks/src/StoreApi/Utilities/OrderController.php +++ b/plugins/woocommerce-blocks/src/StoreApi/Utilities/OrderController.php @@ -44,6 +44,9 @@ class OrderController { * @param \WC_Order $order The order object to update. */ public function update_order_from_cart( \WC_Order $order ) { + // Ensures Local pickups are accounted for. + add_filter( 'woocommerce_order_get_tax_location', array( $this, 'handle_local_pickup_taxes' ) ); + // Ensure cart is current. wc()->cart->calculate_shipping(); wc()->cart->calculate_totals(); @@ -434,6 +437,23 @@ class OrderController { return 'checkout-draft'; } + /** + * Passes the correct base for local pick orders + * + * @todo: Remove custom local pickup handling once WooCommerce 6.8.0 is the minimum version. + * + * @param array $location Taxes location. + * @return array updated location that accounts for local pickup. + */ + public function handle_local_pickup_taxes( $location ) { + $customer = wc()->customer; + + if ( ! empty( $customer ) ) { + return $customer->get_taxable_address(); + } + + return $location; + } /** * Create order line items. *