diff --git a/includes/class-wc-order-item-tax.php b/includes/class-wc-order-item-tax.php index 821c2e68edd..890a3cfea13 100644 --- a/includes/class-wc-order-item-tax.php +++ b/includes/class-wc-order-item-tax.php @@ -77,7 +77,7 @@ class WC_Order_Item_Tax extends WC_Order_Item { * @throws WC_Data_Exception */ public function set_tax_total( $value ) { - $this->set_prop( 'tax_total', wc_format_decimal( $value ) ); + $this->set_prop( 'tax_total', $value ? wc_format_decimal( $value ) : 0 ); } /** @@ -86,7 +86,7 @@ class WC_Order_Item_Tax extends WC_Order_Item { * @throws WC_Data_Exception */ public function set_shipping_tax_total( $value ) { - $this->set_prop( 'shipping_tax_total', wc_format_decimal( $value ) ); + $this->set_prop( 'shipping_tax_total', $value ? wc_format_decimal( $value ) : 0 ); } /** diff --git a/tests/unit-tests/order-items/order-item-tax.php b/tests/unit-tests/order-items/order-item-tax.php new file mode 100644 index 00000000000..273bd9d1499 --- /dev/null +++ b/tests/unit-tests/order-items/order-item-tax.php @@ -0,0 +1,49 @@ +assertEquals( 0, $item->get_tax_total() ); + + $item->set_tax_total( "1.50" ); + $this->assertEquals( "1.50", $item->get_tax_total() ); + + $item->set_tax_total( "" ); + $this->assertEquals( 0, $item->get_tax_total() ); + + $item->set_tax_total( 10.99 ); + $this->assertEquals( "10.99", $item->get_tax_total() ); + } + + /** + * Test set_tax_total/get_tax_total. + * + * @since 3.0.0 + */ + function test_set_get_shipping_tax_totals() { + + $item = new WC_Order_Item_Tax; + $this->assertEquals( 0, $item->get_shipping_tax_total() ); + + $item->set_shipping_tax_total( "1.50" ); + $this->assertEquals( "1.50", $item->get_shipping_tax_total() ); + + $item->set_shipping_tax_total( "" ); + $this->assertEquals( 0, $item->get_shipping_tax_total() ); + + $item->set_shipping_tax_total( 10.99 ); + $this->assertEquals( "10.99", $item->get_shipping_tax_total() ); + } +}