I am trying to set up a dimensional weight counting method when the dimensional weight (width x height x length) of the product is greater than the weight (actual weight).
I found Custom Woocommerce product weight calculation from dimensions answer code that works perfectly.
However I would like to make it works only for specific shipping method(s). Any advice or help?
add_filter( 'woocommerce_product_get_weight', 'custom_get_weight_from_dimensions', 10, 2 );
function custom_get_weight_from_dimensions( $weight, $product ) {
$chosen_shipping = WC()->session->get('chosen_shipping_methods')[0];
// How to restrict to specific shipping methods?
$dim_weight = $product->get_length() * $product->get_width() * $product->get_height() / 5000;
return $dim_weight > $weight ? $dim_weight : $weight;
}