When adding products to my woocommerce store I set weight (in kg) and dimensions (in cm). If [(Height x Length x Width) / 5000] is higher than actual weight then I want this to be used to calculate shipping.
I thought I could use a filter to manipulate $weight but with no success. Here is my code:
function woocommerce_product_get_weight_from_dimensions( $weight ) {
global $product;
$product = wc_get_product( id );
$prlength = $product->get_length();
$prwidth = $product->get_width();
$prheight = $product->get_height();
$dimensions = $prlength * $prwidth * $prheight;
$dweight = $dimensions / 5000;
if ($dweight > $weight) {
return $dweight;
}
return $weight;
}
add_filter('woocommerce_product_get_weight', 'woocommerce_product_get_weight_from_dimensions');
What am i doing wrong?