Woocommerce. Max weight per order based on shipping class

This will do it:

add_action('woocommerce_check_cart_items','check_cart_weight');
add_action('woocommerce_checkout_process', 'check_cart_weight' );

function check_cart_weight()
    {
    $cart = WC()->cart;
    if(!$cart) return;
    $weight = 0;
    foreach($cart->get_cart_contents() as $item)
        {
        if(!isset($item['product_id'])) continue;
        $prod = wc_get_product($item['product_id']);
        if($prod->get_shipping_class()!=='sypkie') continue;
        $weight += ($item['quantity'] * (float)$prod->get_weight());
        };
    if( $weight > 125 )
        {
        $error =  sprintf( __( 'You have %sKg weight and we allow only 125Kg of weight per order.', 'woocommerce' ), $weight);
        if(is_checkout()) { wc_add_notice($error, 'error'); } else { wc_print_notice($error, 'error'); };
        };
    }

This goes through items in the cart, checks their shipping class (matching by the slug of the shipping class) and adds their weight up. I’ve also added the same function to the action woocommerce_checkout_process which shows the same message on the checkout page.