diff --git a/module-admin/init-zones.php b/module-admin/init-zones.php index 6756179..0217d3d 100644 --- a/module-admin/init-zones.php +++ b/module-admin/init-zones.php @@ -125,14 +125,30 @@ private function _calculate_weight($package) { global $woocommerce; $weight = wc_get_weight($woocommerce->cart->cart_contents_weight, 'g'); + // calculate volume + // @warn - Setting default to "1" can cause item to be much larger if unit is set to "inch" + $volume = array_reduce($woocommerce->cart->get_cart_contents(), function($result, $item) { + $product = $item['data']; + $length = (int) $product->get_length() ?? 1; + $width = (int) $product->get_width() ?? 1; + $height = (int) $product->get_height() ?? 1; + $result += $length * $width * $height; + return $result; + }, 0); + + $volume = wc_get_dimension($volume, 'cm'); + $weight_volume = $volume / 6; //@todo: make this formula into a setting + + // if volume is heavier than weight, use the volume + $weight = $weight_volume > $weight ? $weight_volume : $weight; + if($weight > 0) { return $weight; } // if no weight data, return default weight or 1kg else { - $weight = (int) ceil(apply_filters('wcis_default_weight', $package)); - - return (is_int($weight) && $weight > 0) ? $weight : 1; + $weight = (int) ceil(apply_filters('wcis_default_weight', 1000)); + return $weight; } } diff --git a/woocommerce-indo-shipping.php b/woocommerce-indo-shipping.php index 9bb6b7a..5cda802 100644 --- a/woocommerce-indo-shipping.php +++ b/woocommerce-indo-shipping.php @@ -5,7 +5,7 @@ Plugin URI: http://github.com/hrsetyono/woocommerce-indo-shipping Author: Pixel Studio Author URI: https://pixelstudio.id/ -Version: 2.0.2 +Version: 2.1.0 */ if(!defined('ABSPATH') ) { exit; } // exit if accessed directly @@ -15,7 +15,7 @@ return; } -define('WCIS_VERSION', '2.0.2'); +define('WCIS_VERSION', '2.1.0'); define('WCIS_PATH', plugins_url('', __FILE__)); define('WCIS_DIR', __DIR__); define('WCIS_NAMESPACE', 'wcis/v1');