Change conditionally cart item shipping class to change shipping cost in WooCommerce

Solution:

In your case woocommerce_cart_shipping_packages hook is the right hook to be used for shipping costs based on shipping class change based on specific conditions like:

add_action('woocommerce_cart_shipping_packages', 'alter_item_shipping_class_for_shipping_cost_change' );
function alter_item_shipping_class_for_shipping_cost_change( $shipping_packages ) {
    foreach ( $shipping_packages as $key => $package ) {
        foreach ( $package['contents'] as $cart_item_key => $cart_item ) {
            if ( true ) {
                $package['contents'][$cart_item_key]['data']->set_shipping_class_id(1947);
            }
        }
    }
    return $shipping_packages;
}

Code goes in functions.php file of the active child theme (or active theme). Tested and works.