Please copy the code to your function.php
/**
* @snippet Display Dimensions @ Cart & Checkout – WooCommerce
* @author toastedweb
* @ based on https://stackoverflow.com/users/3730754/loictheaztec
*/
add_action( ‘woocommerce_checkout_before_customer_details’, ‘get_cart_volume’ );
add_action( ‘woocommerce_before_cart’, ‘get_cart_volume’ );
function get_cart_volume(){
// Initializing variables
$volume = $rate = 0;
// Get the dimetion unit set in Woocommerce
$dimension_unit = get_option( ‘woocommerce_dimension_unit’ );
// Calculate the rate to be applied for volume in m3
if ( $dimension_unit == ‘mm’ ) {
$rate = pow(10, 9);
} elseif ( $dimension_unit == ‘cm’ ) {
$rate = pow(10, 6);
} elseif ( $dimension_unit == ‘m’ ) {
$rate = 1;
}
if( $rate == 0 ) return false; // Exit
// Loop through cart items
foreach(WC()->cart->get_cart() as $cart_item) {
// Get an instance of the WC_Product object and cart quantity
$product = $cart_item[‘data’];
$qty = $cart_item[‘quantity’];
// Get product dimensions
$length = $product->get_length();
$width = $product->get_width();
$height = $product->get_height();
// Calculations a item level
$volume += $length * $width * $height * $qty;
$inm = $volume / $rate ;
$last = ‘Volume (Cubic Meter) m3: ‘ . $inm;
}
wc_print_notice( $last, ‘notice’ );
}