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 … Read more