Support » Plugin: WPAdverts - Classifieds Plugin » Pre-fill phone number in every advert listing

  • Resolved newarkcomputers

    (@newarkcomputers)


    Hello,

    How do i get it so when your posting an advert it pre-fills your phone number from your profile in the phone number box please?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    you can prefill the phone number by adding the code below

    
    add_action( "adverts_form_bind", function( $form ) {
        $phone = get_user_meta( get_current_user_id(),'phone_number',true );
        $form->set_value( "adverts_phone", $phone );
        return $form;
    }, 1000 );
    

    This will work assuming the user phone number is stored in wp_usermeta table in field named “phone_number”.

    By default the WordPress does not have a phone number field in user profiles so i am assuming you are using some custom plugin to add it?

    newarkcomputers

    (@newarkcomputers)

    Where does this code go exactly please?

    I want the phone number to pre-fill from the author profile

    “user_phone”

    Plugin Author Greg Winiarski

    (@gwin)

    The code you can add in your theme functions.php file.

    To get phone number from the Author profile use the code below

    
    add_action( "adverts_form_bind", function( $form ) {
        $args = array(
            'author'         =>  wp_get_current_user()->ID,
            'post_type'      => 'advert-author',
            'posts_per_page' => 1,
            'post_status'    => array( 'publish', 'advert-hidden' ),
        );
    
        $author_page = get_posts( $args );
        $phone = get_post_meta( $author_page[0]->ID, "user_phone", true );
        $form->set_value( "adverts_phone", $phone );
        return $form;
    }, 1000 );
    
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Pre-fill phone number in every advert listing’ is closed to new replies.