BuddyDev

Search

Whatsapp me Button

  • Participant
    Level: Initiated
    Posts: 1
    vmal on #47811

    Hi im stuck to create a button on buddy press user profile to which on click opens up wtasapp to start a conversations.

    I need a button with ref to > https://wa.me/{user number}, were on click, the user phone number will be retrieved and appended to the link above.

    Ive managed to add a custom button using

    ‘function buddydev_add_custom_buttons( $buttons ) {

    if ( ! bp_is_my_profile() ) {
    return $buttons;
    }

    $buttons[‘contact’] = array(
    ‘id’ => ‘buddydev_contact’,
    ‘component’ => ‘members’,
    ‘must_be_logged_in’ => true,
    ‘button_element’ => ‘a’,
    ‘link_text’ => __( ‘Contact me’ ),
    ‘button_attr’ => array(
    ‘href’ => esc_url( ‘https://wa.me/{user number}’ ),
    ‘title’ => __( ‘Contact Me’ ),
    )
    );

    return $buttons;
    }

    add_filter( ‘bp_nouveau_get_members_buttons’, ‘buddydev_add_custom_buttons’ );’

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2952
    Ravi on #47812

    Hello

    Welcome to the BuddyDev forums. Please try the following way:

    
    
    function buddydev_add_custom_buttons( $buttons ) {
    
    	if ( ! bp_is_user() || bp_is_my_profile() ) {
    		return $buttons;
    	}
    
    	if ( ! bp_is_active( 'xprofile' ) ) {
    		return $buttons;
    	}
    
    	// Replace field id with your phone number field id.
    	$phone_number = xprofile_get_field_data( 28, bp_displayed_user_id(), 'string' );
    
    	// You can also validate weather phone number valid or not.
    	if ( $phone_number ) {
    		$buttons['contact'] = array(
    			'id'                => 'buddydev_contact',
    			'component'         => 'members',
    			'must_be_logged_in' => true,
    			'button_element'    => 'a',
    			'link_text'         => __( 'Contact me' ),
    			'button_attr'       => array(
    				'href'  => esc_url( "https://wa.me/{$phone_number}" ),
    				'title' => __( 'Contact Me' ),
    			)
    		);
    	}
    
    	return $buttons;
    }
    
    add_filter( 'bp_nouveau_get_members_buttons', 'buddydev_add_custom_buttons' );
    
    

    Please let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 1
    vmal on #47831

    Hi ravi, unfortunately the button disappears completely with the new code. Btw, may i know how to refer the user data mapping for their respective input? ‘xprofile_get_field_data( 28, bp_displayed_user_id(), ‘string’ );’ > seems you have used 28 for contact?

You must be logged in to reply to this topic.

This topic is: not resolved