Update abstract-wc-order.php

If the order has no shipping line, there must not generate an unnecessary shipping tax line with 0 value. It was happened if there is set a different tax class for shipping than tax classes of the actual product line items of the order, and the order has not got any shipping line.
The aim is to have the same tax calculation behavior if we create orders using the GUI (front end or back end), and the API.

This condition prevents to create the unnecessary tax line if there is no shipping methods of the order:

// Now calculate shipping tax
$matched_tax_rates = array();
$shipping_methods = $this->get_shipping_methods();
if ( ! empty( $shipping_methods ) ) {
	......
}


This conditional solution is similar than calc_line_taxes() in WC_AJAX class:

// Get shipping taxes
if ( isset( $items['shipping_method_id'] ) ) {
	.....
}
This commit is contained in:
Peter 2015-12-21 23:42:59 +01:00
parent 997d1caa50
commit 458c755b5f
1 changed files with 10 additions and 7 deletions

View File

@ -684,13 +684,16 @@ abstract class WC_Abstract_Order {
// Now calculate shipping tax
$matched_tax_rates = array();
$tax_rates = WC_Tax::find_rates( array(
'country' => $country,
'state' => $state,
'postcode' => $postcode,
'city' => $city,
'tax_class' => ''
) );
$shipping_methods = $this->get_shipping_methods();
if ( ! empty( $shipping_methods ) ) {
$tax_rates = WC_Tax::find_rates( array(
'country' => $country,
'state' => $state,
'postcode' => $postcode,
'city' => $city,
'tax_class' => ''
) );
}
if ( ! empty( $tax_rates ) ) {
foreach ( $tax_rates as $key => $rate ) {