• Hello,

    I would like to prepopulate the phone number field for logged in users and wondered if there’s a shortcode like default:user_phone available. If not, could you please provide me a short snippet / hook to achieve this?

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    WordPress by default doesn’t have a phone number field in user profile.

    Thread Starter bibberle

    (@bibberle)

    true. Managed it by using the following Code. Do you see any problems using this code?

    function contact_form_prepopulate() {
    
    	$user = wp_get_current_user();
    	$userid =  $user->ID;
    
    	if($userid)
    	{
    		
    		// Contact form 7 Prepopulate
    		$wpcf7 = WPCF7_ContactForm::get_current();
    		if(is_object($wpcf7))
    		{
    			$phone = $user->billing_phone;
    			if($phone)
    			{
    				?>
    
    				<script>
    					setTimeout(
    					  function() 
    					  {
    							jQuery(".wpcf7-tel").val('<?php echo $phone; ?>');
    
    					  }, 500);
    				</script>
    				<?php
    			}
    			
    			$company = $user->billing_company;
    			if($company)
    			{
    				?>
    				<script>
    					setTimeout(
    					  function() 
    					  {
    							jQuery(".wpcf7-text[name='Firma']").val("<?php echo $company; ?>");
    
    					  }, 500);
    
    				</script>
    				<?php
    			}
    		}
    	}
    }
    add_action( 'wp_footer', 'contact_form_prepopulate', 99 );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Pre-Populate phone number for logged in users’ is closed to new replies.