Merge pull request #17817 from JeroenSormani/exclude-virtual-from-shipping-tax
Exclude virtual tax classes from calcluation for shipping taxes
This commit is contained in:
commit
8b02185596
|
@ -1520,7 +1520,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
|
|||
* @return bool
|
||||
*/
|
||||
public function is_shipping_taxable() {
|
||||
return $this->get_tax_status() === 'taxable' || $this->get_tax_status() === 'shipping';
|
||||
return $this->needs_shipping() && ( $this->get_tax_status() === 'taxable' || $this->get_tax_status() === 'shipping' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -981,6 +981,23 @@ class WC_Cart extends WC_Legacy_Cart {
|
|||
return array_unique( $found_tax_classes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all tax classes for shipping based on the items in the cart.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_cart_item_tax_classes_for_shipping() {
|
||||
$found_tax_classes = array();
|
||||
|
||||
foreach ( WC()->cart->get_cart() as $item ) {
|
||||
if ( $item['data'] && ( $item['data']->is_shipping_taxable() ) ) {
|
||||
$found_tax_classes[] = $item['data']->get_tax_class();
|
||||
}
|
||||
}
|
||||
|
||||
return array_unique( $found_tax_classes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the value that the customer spent and the subtotal
|
||||
* displayed, used for things like coupon validation.
|
||||
|
|
|
@ -579,7 +579,7 @@ class WC_Tax {
|
|||
} 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();
|
||||
$cart_tax_classes = WC()->cart->get_cart_item_tax_classes_for_shipping();
|
||||
|
||||
// No tax classes = no taxable items.
|
||||
if ( empty( $cart_tax_classes ) ) {
|
||||
|
|
Loading…
Reference in New Issue