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