Okay
  Public Ticket #3662794
Add Customer Field Requirements
Closed

Comments

  •  4
    Marissa Stankiewicz started the conversation

    Hello,

    When agents use the 'add customer' form, the following fields are required:

    First Name, Last Name, User Name, Email, Password. 

    I've found your article on removing fields - https://woocommerce-b2b-plugin.com/docs/how-to-add-or-remove-fields-from-new-customer-form/  

    However, is there a suggested fix to make them 'optional'? After all- it's possible to register someone with just an email address in the register form, correct? 

  •  2,219
    WebWizards replied

    Hello Marissa,


    -> It is possible to make the first and last name fields optional with a snippet

    -> For email, username, password, I do not have a way to make them optional. However, we can hide them + set SalesKing to auto-generate random values. That way customers would be created with a random username and email such as Lk2K9e8dHe9z7m


    For all that, you can add the following PHP code snippet to your site:

    add_action('salesking_dashboard_head', function(){
        ?>
        <script>
            jQuery(document).ready(function(){
                jQuery('#salesking_add_customer_form #username').parent().parent().remove();
                jQuery('#salesking_add_customer_form #email-address').parent().parent().remove();
                jQuery('#salesking_add_customer_form #password').parent().parent().remove();
                jQuery('#first-name').prop('required', false);
                jQuery('#last-name').prop('required', false);
            });
        </script>
        <?php
    });
    add_filter('salesking_filter_newcustomer_username', function($user){
        return wp_generate_password(12, false);
    }, 10, 1);
    add_filter('salesking_filter_newcustomer_email', function($email){
        return wp_generate_password(12, false).'@gmail.com';
    }, 10, 1);
    add_filter('salesking_filter_newcustomer_password', function($password){
        return wp_generate_password();
    }, 10, 1);

    It makes first/last name optional + it removes user/email/password fields.


    Kind regards,

    Stefan

  •  4
    Marissa Stankiewicz replied

    Wonderful solution. Thank you for your help.