Skip to content
Snippets Groups Projects
Commit 9d7aa991 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Add checks to use length/width/height/volume only if they are defined for a...

Add checks to use length/width/height/volume only if they are defined for a product. Default of 0 will be used otherwise
parent ed53cabf
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment