From 9d7aa9913df58990eea53deec49a4b97e1dbf07b Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sat, 7 Oct 2017 20:38:42 +0200 Subject: [PATCH] Add checks to use length/width/height/volume only if they are defined for a product. Default of 0 will be used otherwise --- .../rules_shipping_framework_woocommerce.php | 35 +++++++++++-------- readme.txt | 2 +- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/includes/rules_shipping_framework_woocommerce.php b/includes/rules_shipping_framework_woocommerce.php index 3199766..fc01c1a 100644 --- a/includes/rules_shipping_framework_woocommerce.php +++ b/includes/rules_shipping_framework_woocommerce.php @@ -152,20 +152,27 @@ class RulesShippingFrameworkWooCommerce extends RulesShippingFramework { $w = $product['data']->get_width(); $h = $product['data']->get_height(); - $volume = $l * $w * $h; - $dimensions['volume'] += $volume * $product['quantity']; - $dimensions['maxvolume'] = max ($dimensions['maxvolume'], $volume); - $dimensions['minvolume'] = min ($dimensions['minvolume'], $volume); - - $dimensions['totallength'] += $l * $product['quantity']; - $dimensions['maxlength'] = max ($dimensions['maxlength'], $l); - $dimensions['minlength'] = min ($dimensions['minlength'], $l); - $dimensions['totalwidth'] += $w * $product['quantity']; - $dimensions['maxwidth'] = max ($dimensions['maxwidth'], $w); - $dimensions['minwidth'] = min ($dimensions['minwidth'], $w); - $dimensions['totalheight'] += $h * $product['quantity']; - $dimensions['maxheight'] = max ($dimensions['maxheight'], $h); - $dimensions['minheight'] = min ($dimensions['minheight'], $h); + if (is_numeric($l) && is_numeric($w) && is_numeric($h)) { + $volume = $l * $w * $h; + $dimensions['volume'] += $volume * $product['quantity']; + $dimensions['maxvolume'] = max ($dimensions['maxvolume'], $volume); + $dimensions['minvolume'] = min ($dimensions['minvolume'], $volume); + } + if (is_numeric($l)) { + $dimensions['totallength'] += $l * $product['quantity']; + $dimensions['maxlength'] = max ($dimensions['maxlength'], $l); + $dimensions['minlength'] = min ($dimensions['minlength'], $l); + } + if (is_numeric($w)) { + $dimensions['totalwidth'] += $w * $product['quantity']; + $dimensions['maxwidth'] = max ($dimensions['maxwidth'], $w); + $dimensions['minwidth'] = min ($dimensions['minwidth'], $w); + } + if (is_numeric($h)) { + $dimensions['totalheight'] += $h * $product['quantity']; + $dimensions['maxheight'] = max ($dimensions['maxheight'], $h); + $dimensions['minheight'] = min ($dimensions['minheight'], $h); + } } return $dimensions; diff --git a/readme.txt b/readme.txt index 5b6af0c..9c8bf4d 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: opentools Tags: WooCommerce, Shipment, Shipping, Rules shipping Requires at least: 4.0 Tested up to: 4.8 -Stable tag: 2.0.1 +Stable tag: 2.0.2 License: GPLv3 or later License URI: http://www.gnu.org/licenses/gpl.html -- GitLab