From 3a2b3d10adf5117dc6519ddd8d6de9fa25dcb27c Mon Sep 17 00:00:00 2001 From: RobertoDonPedro Date: Thu, 17 Jan 2019 13:57:31 +0100 Subject: [PATCH 1/2] Filter get_item_tax_rates in class-wc-cart-totals.php Adds filter on the return value of function 'get_item_tax_rates' to prevent the mandatory caching of tax rates, described in https://github.com/woocommerce/woocommerce/issues/21855 --- includes/class-wc-cart-totals.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-cart-totals.php b/includes/class-wc-cart-totals.php index 55bf6d5e072..fc56a1c03dd 100644 --- a/includes/class-wc-cart-totals.php +++ b/includes/class-wc-cart-totals.php @@ -485,7 +485,9 @@ final class WC_Cart_Totals { return array(); } $tax_class = $item->product->get_tax_class(); - return isset( $this->item_tax_rates[ $tax_class ] ) ? $this->item_tax_rates[ $tax_class ] : $this->item_tax_rates[ $tax_class ] = WC_Tax::get_rates( $item->product->get_tax_class(), $this->cart->get_customer() ); + $taxrates = isset( $this->item_tax_rates[ $tax_class ] ) ? $this->item_tax_rates[ $tax_class ] : $this->item_tax_rates[ $tax_class ] = WC_Tax::get_rates( $item->product->get_tax_class(), $this->cart->get_customer() ); + $taxrates = apply_filters( 'woocommerce_item_tax_rates', $taxrates, $item, $this->cart ); + return $taxrates; } /** From 2d14315f3d3bb76362a619bb311058b00a27e4dd Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 21 Jan 2019 15:38:48 +0000 Subject: [PATCH 2/2] woocommerce_cart_totals_get_item_tax_rates --- includes/class-wc-cart-totals.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-cart-totals.php b/includes/class-wc-cart-totals.php index fc56a1c03dd..614e46bd5c3 100644 --- a/includes/class-wc-cart-totals.php +++ b/includes/class-wc-cart-totals.php @@ -484,10 +484,11 @@ final class WC_Cart_Totals { if ( ! wc_tax_enabled() ) { return array(); } - $tax_class = $item->product->get_tax_class(); - $taxrates = isset( $this->item_tax_rates[ $tax_class ] ) ? $this->item_tax_rates[ $tax_class ] : $this->item_tax_rates[ $tax_class ] = WC_Tax::get_rates( $item->product->get_tax_class(), $this->cart->get_customer() ); - $taxrates = apply_filters( 'woocommerce_item_tax_rates', $taxrates, $item, $this->cart ); - return $taxrates; + $tax_class = $item->product->get_tax_class(); + $item_tax_rates = isset( $this->item_tax_rates[ $tax_class ] ) ? $this->item_tax_rates[ $tax_class ] : $this->item_tax_rates[ $tax_class ] = WC_Tax::get_rates( $item->product->get_tax_class(), $this->cart->get_customer() ); + + // Allow plugins to filter item tax rates. + return apply_filters( 'woocommerce_cart_totals_get_item_tax_rates', $item_tax_rates, $item, $this->cart ); } /**