Merge pull request #16336 from woocommerce/fix/16241

Only return tax classes if product is taxable.
This commit is contained in:
Claudiu Lodromanean 2017-08-07 10:02:02 -07:00 committed by GitHub
commit dd094088b0
4 changed files with 12 additions and 5 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

@ -553,11 +553,16 @@ class WC_Tax {
'tax_class' => $tax_class,
) );
} else {
} elseif ( WC()->cart->get_cart() ) {
// 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();

View File

@ -63,7 +63,7 @@ class WC_Tests_Tax extends WC_Unit_Test_Case {
$tax_rates = WC_Tax::get_shipping_tax_rates();
$this->assertEquals( $tax_rates, array( $tax_rate_id => array( 'rate' => '20.0000', 'label' => 'VAT', 'shipping' => 'yes', 'compound' => 'no' ) ) );
$this->assertEquals( $tax_rates, array( $tax_rate_id => array( 'rate' => '20.0000', 'label' => 'VAT', 'shipping' => 'yes', 'compound' => 'no' ) ), print_r( $tax_rates, true ) );
WC_Tax::_delete_tax_rate( $tax_rate_id );
}