Add custom fields in new customer form in sales agents dashboard

Saturday, 28 August 2021

WooCommerce B2B Sales Agents allows sales agents to create new customers from their dashboard, if the “NEW CUSTOMERS” option is enabled on the plugin settings page. In the same section, it is also possible to enable the extension of the customer registration form present right in the dashboard, by adding the predefined WooCommerce billing fields.
If you wish to further customize this form, without intervening on the standard registration form, you can use the special hook we have introduced for this purpose. To add a custom field to the new customer registration form in the sales agent dashboard, edit functions.php file that you find in your site’s FTP space in:


and insert this code:

add_filter( 'wcb2bsa_new_customer_form_fields', function( $fields ) {
    $fields['YOUR_CUSTOM_FIELD_KEY'] = array(
        'type' => 'text',
        'class' => array( 'form-group' ),
        'input_class'   => array( 'form-control' ),
        'label'         => esc_html__( 'YOUR CUSTOM FIELD LABEL', 'woocommerce-b2b-sales-agents' ),
        'required'      => false,
    return $fields;
} );
WARNING! Before making any changes, make sure you have made a complete backup of site files and database.
It is advisable not to edit the theme files directly, but to use a child theme.
For more information on child themes, please read: WordPress Official guide on Child Themes