diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index a9e77d0c16e..71ec1b30703 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -992,8 +992,8 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { $found_tax_classes = array(); foreach ( $this->get_items() as $item ) { - if ( $_product = $item->get_product() ) { - $found_tax_classes[] = $_product->get_tax_class(); + if ( ( $product = $item->get_product() ) && ( $product->is_taxable() || $product->is_shipping_taxable() ) ) { + $found_tax_classes[] = $product->get_tax_class(); } } diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php index e0edaa7cc3f..dfcfcb22f27 100644 --- a/includes/class-wc-cart.php +++ b/includes/class-wc-cart.php @@ -775,7 +775,9 @@ class WC_Cart { $found_tax_classes = array(); foreach ( WC()->cart->get_cart() as $item ) { - $found_tax_classes[] = $item['data']->get_tax_class(); + if ( $item['data'] && ( $item['data']->is_taxable() || $item['data']->is_shipping_taxable() ) ) { + $found_tax_classes[] = $item['data']->get_tax_class(); + } } return array_unique( $found_tax_classes ); diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php index a0c72452db3..e458dc68ee3 100644 --- a/includes/class-wc-tax.php +++ b/includes/class-wc-tax.php @@ -558,6 +558,11 @@ class WC_Tax { // This will be per order shipping - loop through the order and find the highest tax class rate $cart_tax_classes = WC()->cart->get_cart_item_tax_classes(); + // No tax classes = no taxable items. + if ( empty( $cart_tax_classes ) ) { + return array(); + } + // If multiple classes are found, use the first one found unless a standard rate item is found. This will be the first listed in the 'additional tax class' section. if ( sizeof( $cart_tax_classes ) > 1 && ! in_array( '', $cart_tax_classes ) ) { $tax_classes = self::get_tax_class_slugs();