Extend User Registration with extra WooCommerce Fields

Hi guys,

I am trying to extend user registration form with more required fields, considering WooCommerce basic fields like so they can be shared between HP and WC:

  • City/Town
  • Zip
  • State
  • Country
  • Phone

I found the snippet that makes First name and Last name required (Make first and last name fields required for users #hivepress #users · GitHub), and extended it in the following way:




add_filter(
    'hivepress/v1/forms/user_update',
    function ($form) {
        // Existing modifications
        $form['fields']['first_name']['required'] = true;
        $form['fields']['last_name']['required'] = true;



        // Add new WooCommerce fields
        $form['fields']['billing_city'] = [
            'label' => esc_html__('City/Town', 'your-text-domain'),
            'type' => 'text',
            'required' => true,
            '_order' => 90,
        ];

        $form['fields']['billing_postcode'] = [
            'label' => esc_html__('Zip', 'your-text-domain'),
            'type' => 'text',
            'required' => true,
            '_order' => 91,
        ];

        $form['fields']['billing_state'] = [
            'label' => esc_html__('State', 'your-text-domain'),
            'type' => 'text',
            'required' => true,
            '_order' => 92,
        ];

        $form['fields']['billing_country'] = [
            'label' => esc_html__('Country', 'your-text-domain'),
            'type' => 'select',
            'options' => WC()->countries->get_countries(),
            'required' => true,
            '_order' => 93,
        ];

        $form['fields']['billing_phone'] = [
            'label' => esc_html__('Phone', 'your-text-domain'),
            'type' => 'text',
            'required' => true,
            '_order' => 94,
        ];



        return $form;
    },
    1000



);

The problem is that saving doesn’t work…? I’ve tried with WC action, but it didn’t resolve saving issues. Any suggestion?

Thanks

Hi,

Thank you for your feedback, we will consider adding this feature.

This version has two workarounds:

  1. Use the snippet above, but add fields with the _external flag to the user model on the hivepress/v1/models/user hook.

  2. Another option is to add the fields as user attributes in Users > Attributes, and just set them as required (then they will appear in the register form and be saved), and then synchronize them with WooCommerce fields using this hook hivepress/v1/models/user/update

​I hope this is helpful to you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.