Only return tax classes if product is taxable.

Fixes #16241
This commit is contained in:
Mike Jolley 2017-08-03 08:44:02 +02:00
parent 52b10d8be4
commit 6af275da6e
3 changed files with 10 additions and 3 deletions

View File

@ -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();
}
}

View File

@ -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 );

View File

@ -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();