• Hi, How can I add a phone number field here(?https://ibb.co/ncxmPRZ?)? After I create a user, I can add a phone number (it’s a WooCommerce field, I think), but I wanted it to show up first when I add a new user.

    • This topic was modified 4 months, 1 week ago by justvimbing.
    • This topic was modified 4 months, 1 week ago by justvimbing.
Viewing 1 replies (of 1 total)
  • Hello @justvimbing

    To add a phone number field to the “Add New User” page in WordPress, you can use the user_new_form action to display the field and user_register to save it. Here’s a concise example:

    // Add phone field to Add New User page
    function custom_add_phone_field($operation) {
    if ($operation !== ‘add-new-user’) return;
    echo ‘Phone Number’;
    }
    add_action(‘user_new_form’, ‘custom_add_phone_field’);

    // Save phone number field
    function custom_save_phone_field($user_id) {
    if (isset($_POST[‘phone’])) update_user_meta($user_id, ‘phone’, sanitize_text_field($_POST[‘phone’]));
    }
    add_action(‘user_register’, ‘custom_save_phone_field’);
    This adds a “Phone Number” field when creating a new user and saves it as user meta.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.