• Resolved ltrost

    (@ltrost0910gmail)


    How can I prefill the email address on the signup form with the info from the currently logged in user so they don’t have to enter it again? I don’t want to capture it at registration or checkout, just on a separate page visible to signed-in users.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ltrost

    (@ltrost0910gmail)

    I got it to work using this snippet, but I’m hoping there’s a better way.

    add_filter( ‘mailpoet_form_widget_post_process’, ‘gsdoc_get_user_email’ );

    function gsdoc_get_user_email( $form ) {
    if( is_user_logged_in() ){
    global $wpdb;
    $current_user2 = wp_get_current_user();
    $pol1 = ‘title=”Email” value=””‘;
    $pol2 = ‘title=”Email” value=”‘ . $current_user2->user_email . ‘”‘;
    $form = str_replace($pol1, $pol2, $form);
    return $form;
    }
    }

    Here it is without quote destruction. It only worked for me when I was brave about substituting any value=””.

    
     function gsdoc_get_user_email( $form ) {
         if( is_user_logged_in() ){
             global $wpdb;
             $current_user2 = wp_get_current_user();
             $pol1 = 'value=""';
             $pol2 = 'value="' . $current_user2->user_email . '"';
             $form = str_replace($pol1, $pol2, $form);
             return $form;
         }
    }
    
    add_filter( 'mailpoet_form_widget_post_process', 'gsdoc_get_user_email' );
    
    • This reply was modified 4 years, 3 months ago by bimargulies.
    • This reply was modified 4 years, 3 months ago by bimargulies.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use current user email to pre-fill the email address on a signup form??’ is closed to new replies.