Okay
  Public Ticket #4189557
Custom Registration Field showing on Users page
Open

Comments

  •  1
    Lindsey started the conversation

    Hi! Is there anyway to add a customer user field to the Users page? We'd love to be able to see "Employee ID" next to their last name so we don't have to jump through hoops to find out who they are when it's been years since they've registered. Code snippets are great, or I have access to the templates.

    Attached files:  Users-‹-Ward-Gear-—-WordPress-07-24-2025_11_21_AM.png

  •  2,479
    WebWizards replied

    Hi Lindsey,

    I understand that you have a B2BKing Registration field and you wish to show that on the main Users page.

    You can use the following code snippet for that:

    // Add custom column header to Users page
    function add_b2bking_custom_field_column($columns) {
        $columns['b2bking_custom_field_1234'] = 'Employee ID'; 
        return $columns;
    }
    add_filter('manage_users_columns', 'add_b2bking_custom_field_column');
    
    // Display the custom field value in the column
    function show_b2bking_custom_field_column_content($value, $column_name, $user_id) {
        if ($column_name == 'b2bking_custom_field_1234') {
            $custom_field_value = get_user_meta($user_id, 'b2bking_custom_field_1234', true);
            return !empty($custom_field_value) ? esc_html($custom_field_value) : '—';
        }
        return $value;
    }
    add_filter('manage_users_custom_column', 'show_b2bking_custom_field_column_content', 10, 3)

    Before using this code, you'll need to replace '1234' with your actual field ID (it appears 3 times in the code). To find your field ID:
    1. Go to B2BKing -> Registration Fields
    2. Edit the Employee ID field
    3. Look at the URL - you'll see something like "?post=123" - that number is your field ID

     

    You can add this code to your theme's functions.php file or using a code snippets plugin.

    Let me know if you need any clarification!

    Kind regards,
    Stefan

  •  1
    Lindsey replied

    Hi Stefan, this is great!

    I'm getting an error from my code snippets plugin: syntax error, unexpected end of file

    I have the registration field ID: 1779.

  •  2,479
    WebWizards replied

    Hi Lindsey,

    In that case the code should be:

    // Add custom column header to Users page
    function add_b2bking_custom_field_column($columns) {
        $columns['b2bking_custom_field_1779'] = 'Employee ID'; 
        return $columns;
    }
    add_filter('manage_users_columns', 'add_b2bking_custom_field_column');
    
    // Display the custom field value in the column
    function show_b2bking_custom_field_column_content($value, $column_name, $user_id) {
        if ($column_name == 'b2bking_custom_field_1779') {
            $custom_field_value = get_user_meta($user_id, 'b2bking_custom_field_1779', true);
            return !empty($custom_field_value) ? esc_html($custom_field_value) : '—';
        }
        return $value;
    }
    add_filter('manage_users_custom_column', 'show_b2bking_custom_field_column_content', 10, 3)

    I did test that successfully on my local test site before sharing the snippet, so I believe it should work. Make sure it is saved as a PHP snippet and that there's no other <?php ?> tag in there somewhere.

     

    I can also check this on your site directly if that would help. I would need a backend login to the site,

     

    Kind regards,

    Stefan