How to set a minimum length for username in Woocommerce? [closed]

Ok I found out the solution.

Because, as I said, WooCommerce has it’s own hooks, first of all I’ve searched for a WooCommerce hook about registration.

I discovered the existence of a hook very similiar to the one used by WordPress: woocommerce_registration_errors. Obviously it works in the same way.

Then I simply replaced the WordPress hook with the WooCommerce one. Here the final snippet you have to insert in your functions.php file:

add_filter( 'woocommerce_registration_errors', 'my_registration_errors', 10, 3 );
function my_registration_errors( $errors, $sanitized_user_login, $user_email ) 
{
    if ( strlen( $sanitized_user_login ) < 5 ) {
        $errors->add( 'username_too_short', __( '<strong>ERROR</strong>: Username must be at least 5 characters.' ) );
    }
    return $errors;
}