Add a fee based on cart items dimensions in Woocommerce

Solution:

Use following code

add_action( 'woocommerce_cart_calculate_fees', 'shipping_dimensions_fee', 10, 1 );
function shipping_dimensions_fee( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    // Your settings (here below)
    $target_height   = 3; // The defined height in cm (equal or over)
    $width_threshold = 25; // The defined item with to set the fee.
    $fee             = 50; // The fee amount

    // Initializing variables
    $total_height    = 0; 
    $apply_fee       = false;

    // Loop through cart items
    foreach( $cart->get_cart() as $cart_item ){
        // Calculating total height
        $total_height += $cart_item['data']->get_height() * $cart_item['quantity'];

        // Checking item with
        if ( $cart_item['data']->get_width() > $width_threshold ) {
            $apply_fee = true;
        }
    }

    // Add the fee
    if( $total_height >= $target_height || $apply_fee ) {
        $cart->add_fee( __( 'Dimensions shipping fee' ), $fee, false );
    }
}

Code goes in function.php file of your active child theme (or active theme). It should works.