From 8f63211f1cc674bc561deaf0bb33e5b814992a70 Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Wed, 3 May 2017 08:31:35 +0200 Subject: [PATCH 1/2] Fix non numeric warning for orders. --- includes/abstracts/abstract-wc-order.php | 4 ++-- includes/class-wc-order-item-product.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index 8ac4276e4de..53a48940f04 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -1194,7 +1194,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { if ( $inc_tax ) { $subtotal = ( $item->get_subtotal() + $item->get_subtotal_tax() ) / max( 1, $item->get_quantity() ); } else { - $subtotal = ( $item->get_subtotal() / max( 1, $item->get_quantity() ) ); + $subtotal = ( intval( $item->get_subtotal() ) / max( 1, $item->get_quantity() ) ); } $subtotal = $round ? number_format( (float) $subtotal, wc_get_price_decimals(), '.', '' ) : $subtotal; @@ -1242,7 +1242,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { if ( $inc_tax ) { $total = ( $item->get_total() + $item->get_total_tax() ) / max( 1, $item->get_quantity() ); } else { - $total = $item->get_total() / max( 1, $item->get_quantity() ); + $total = intval( $item->get_total() ) / max( 1, $item->get_quantity() ); } $total = $round ? round( $total, wc_get_price_decimals() ) : $total; diff --git a/includes/class-wc-order-item-product.php b/includes/class-wc-order-item-product.php index 04a73fd53e1..c6a4346f0e6 100644 --- a/includes/class-wc-order-item-product.php +++ b/includes/class-wc-order-item-product.php @@ -96,7 +96,7 @@ class WC_Order_Item_Product extends WC_Order_Item { * @throws WC_Data_Exception */ public function set_subtotal( $value ) { - $this->set_prop( 'subtotal', wc_format_decimal( $value ) ); + $this->set_prop( 'subtotal', intval( wc_format_decimal( $value ) ) ); } /** @@ -106,7 +106,7 @@ class WC_Order_Item_Product extends WC_Order_Item { * @throws WC_Data_Exception */ public function set_total( $value ) { - $this->set_prop( 'total', wc_format_decimal( $value ) ); + $this->set_prop( 'total', intval( wc_format_decimal( $value ) ) ); // Subtotal cannot be less than total if ( ! $this->get_subtotal() || $this->get_subtotal() < $this->get_total() ) { From f493afe7184183eba8b742820c01869abbc6a438 Mon Sep 17 00:00:00 2001 From: Boro Sitnikovski Date: Thu, 4 May 2017 10:09:16 +0200 Subject: [PATCH 2/2] intval -> floatval --- includes/abstracts/abstract-wc-order.php | 4 ++-- includes/class-wc-order-item-product.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index 53a48940f04..1ea430096cf 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -1194,7 +1194,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { if ( $inc_tax ) { $subtotal = ( $item->get_subtotal() + $item->get_subtotal_tax() ) / max( 1, $item->get_quantity() ); } else { - $subtotal = ( intval( $item->get_subtotal() ) / max( 1, $item->get_quantity() ) ); + $subtotal = ( floatval( $item->get_subtotal() ) / max( 1, $item->get_quantity() ) ); } $subtotal = $round ? number_format( (float) $subtotal, wc_get_price_decimals(), '.', '' ) : $subtotal; @@ -1242,7 +1242,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order { if ( $inc_tax ) { $total = ( $item->get_total() + $item->get_total_tax() ) / max( 1, $item->get_quantity() ); } else { - $total = intval( $item->get_total() ) / max( 1, $item->get_quantity() ); + $total = floatval( $item->get_total() ) / max( 1, $item->get_quantity() ); } $total = $round ? round( $total, wc_get_price_decimals() ) : $total; diff --git a/includes/class-wc-order-item-product.php b/includes/class-wc-order-item-product.php index c6a4346f0e6..dc587755a0f 100644 --- a/includes/class-wc-order-item-product.php +++ b/includes/class-wc-order-item-product.php @@ -96,7 +96,7 @@ class WC_Order_Item_Product extends WC_Order_Item { * @throws WC_Data_Exception */ public function set_subtotal( $value ) { - $this->set_prop( 'subtotal', intval( wc_format_decimal( $value ) ) ); + $this->set_prop( 'subtotal', floatval( wc_format_decimal( $value ) ) ); } /** @@ -106,7 +106,7 @@ class WC_Order_Item_Product extends WC_Order_Item { * @throws WC_Data_Exception */ public function set_total( $value ) { - $this->set_prop( 'total', intval( wc_format_decimal( $value ) ) ); + $this->set_prop( 'total', floatval( wc_format_decimal( $value ) ) ); // Subtotal cannot be less than total if ( ! $this->get_subtotal() || $this->get_subtotal() < $this->get_total() ) {