Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
Added comparison to Weight and Volume when calculating shipping cost. Using `volume / 6000` formula
  • Loading branch information
hrsetyono committed Jan 17, 2022
1 parent 43fc808 commit 1dc1563
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
22 changes: 19 additions & 3 deletions module-admin/init-zones.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions woocommerce-indo-shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down

0 comments on commit 1dc1563

Please sign in to comment.