Override email_exists function

Note: The reason this doesn’t work for the OP is the use of woocommerce, otherwise, so in regards of core WordPress functionality, this should be working as described.


Update:

I assumed it is about emails on registration. Good thing you specified your needs. WordPress tries – several checks are performed – to add the new user with wp_insert_usersource: user.php. There you have the filter pre_user_email, which you can use for your purpose.

The exemplary usage would be like this:

add_filter(
    'pre_user_email',
    'wpse163079_pre_user_email_example'
);
function wpse163079_pre_user_email_example(
    $user_email
) {
    if ( email_exists( $user_email ) ) {
        // code that generates the random email address
        // do not forget to check if the random one does exist
        // assign random address as new $user_email then
        return $user_email;
    } else {
        return $user_email;
    }
}


You can’t override email_exists() as it isn’t a pluggable function. But a look into the source: user.php shows:

function email_exists( $email ) {
        if ( $user = get_user_by('email', $email) )
                return $user->ID;

       return false;
}

So email_exists() uses get_user_by()source: pluggable.php -, which on the other hand is a pluggable function, so that one you could override. As you can see get_user_by() does look like this:

function get_user_by( $field, $value ) {
        $userdata = WP_User::get_data_by( $field, $value );

        if ( !$userdata )
                return false;

        $user = new WP_User;
        $user->init( $userdata );

        return $user;
}

So no hook – action or filter – you could use. But it shows that is mainly a wrapper for functionality of the WP_User class – source: capabilities.php. After taking a look at the get_data_by() method of the WP_User class you will see there is no hook available.

You did not write what you are trying to do. Maybe you can achieve what you want by simply overriding get_user_by(). Another possibility could be to additionally extend the WP_User class. I really can’t say much more with the given information, but this should be a good starting point for you.