BuddyDev

Search

Dynamic change of Name Profile field label based on member type selection

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #48291

    Hi Brajesh,

    Please how can I change the Name Label in the registration page and profile details page based on member type selected this should also work with the member types pro conditional selection.

    Kindly see rough work below

     // Function to change the label of the Name field in BuddyPress based on member type
    function change_buddypress_name_field_label( $label, $field ) {
        // Check if the field is the Name field
        if ( $field->name === 'Full Name' ) {
            // Get the current user's member type
            $member_type = bp_get_member_type( bp_loggedin_user_id() );
            // Change the label based on the member type
            switch ( $member_type ) {
                case 'personal':
                    $label = 'First & Last Name';
                    break;
                case 'business':
                    $label = 'Business Name';
                    break;
                case 'organization':
                    $label = 'Organization Name';
                    break;
            }
        }
        return $label;
    }
    
    // Hook the function to the bp_xprofile_field_name_before_save filter
    add_filter( 'bp_xprofile_field_name_before_save', 'change_buddypress_name_field_label', 10, 2 ); 
     // Function to change the label of the Name field in BuddyPress registration page based on member type
    function change_buddypress_registration_name_field_label( $fields ) {
        // Get the selected member type
        $member_type = $_POST['field_1'];
        // Change the label of the Name field based on the selected member type
        switch ( $member_type ) {
            case 'personal':
                $fields['field_2']['name'] = 'First & Last Name';
                break;
            case 'business':
                $fields['field_2']['name'] = 'Business Name';
                break;
            case 'organization':
                $fields['field_2']['name'] = 'Organization Name';
                break;
        }
        return $fields;
    }
    
    // Hook the function to the xprofile_screen_register action
    add_action( 'xprofile_screen_register', 'change_buddypress_registration_name_field_label' ); 

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24262
    Brajesh Singh on #48297

    Hi Tosin,
    I am sorry, we lack the free time to assist you with custom code.
    Also, my suggestion would be to have different fields based on member type instead of doing this manipulations.

    Regards
    Brajesh

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #48320

    Hello Brajesh

    I would also prefer to use different fields but the issue is the (Name) field is the default primary buddypress registration field which handles names across the entire buddypress pages. This field cannot be duplicated and member types pro cannot apply conditional visibility to the field.

    Where this is an issue is I don’t want the field label name to be the generic (Name) but I want it to be more contextual like (First & Last Name), (Business Name) according to the selected member type.

    For Example

    When users register they only input only their first name instead of both first and last name because the label is just (Name) but If I use the label (First & Last Name) this will add more context for the type of data needed. Now the other problem is if I use the label (First & Last Name) and a user selects the member type BUSINESS then I feel the appropriate label now needs to change to (Business Name).

    Thanks

  • Participant
    Level: Guru
    Posts: 886
    Tosin on #48321

    This plugin https://wordpress.org/plugins/bp-profile-field-duplicator/ can be used to duplicate the (Name) field but the newly duplicated fields cannot be made to be the (PRIMARY) name field

You must be logged in to reply to this topic.

This topic is: not resolved