/** * Deny checkout based on cart weight */ add_action('woocommerce_before_cart', 'cc_deny_checkout_by_weight', 99); add_action('woocommerce_before_checkout_form', 'cc_deny_checkout_by_weight', 99); add_action('woocommerce_after_checkout_validation', 'cc_deny_checkout_by_weight', 99); function cc_deny_checkout_by_weight($posted) { $max_weight = 100; if (WC()->cart->cart_contents_weight > $max_weight) { $notice = 'Sorry, your cart has exceeded the maximum allowed weight of ' . $max_weight . get_option('woocommerce_weight_unit'); if( is_cart() ) { wc_print_notice($notice, 'error'); } else { wc_add_notice($notice, 'error'); } } }