I think you should use wordpress hooks like you already using in your email template:
apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' )
Instead of directly writing like this
global $current_user;
get_currentuserinfo();
echo '<h4>Your code:</h3>' . $current_user->ID . '';
You could apply filter like this
global $current_user;
apply_filters( 'woocommerce_custom_template_email', $current_user->ID );
And when email function responsible for sending emails is triggered you use add_filter like this
add_filters( 'woocommerce_custom_template_email', 'custom_email_function' );
function custom_email_function($user_id) {
global $current_user;
$user_id = $current_user->ID;
return $user_id;
}
Maybe in this way you can get current user id. Alse make shure that you are trying to get current user id for logged in users.