How to avoid jumping up on woocommerce registration, to ajaxify the form or some other way?

37 Views Asked by At

The registration form by default is jumping up if user makes the error and shows the error only in one field, even if all required fields are empty. It's annoying. I have many extra-fields in this register form - like billing phone, billing address - mostly all from checkout. Added by code without plugins. So a popular plugin for ajaxifying the process is not what will help.

For checkout, I found the cool decision by BusinessBloomer - errors as labels

add_filter( 'woocommerce_form_field', 'bbloomer_checkout_fields_in_label_error', 10, 4 );
 
function bbloomer_checkout_fields_in_label_error( $field, $key, $args, $value ) {
   if ( strpos( $field, '</label>' ) !== false && $args['required'] ) {
      $error = '<span class="error" style="display:none">';
      $error .= sprintf( __( '%s is a required field.', 'woocommerce' ), $args['label'] );
      $error .= '</span>';
      $field = substr_replace( $field, $error, strpos( $field, '</label>' ), 0);
   }
   return $field;
}

If users have an error - it would appear exactly in the field. If there are errors in all fields- after submit all appears already, not 1 by 1 after every submit.

To cut and paste the errors from top to fields I used jQuery, it helped with 10 fields and didn't help with 3, but they are still appear 1 by one, and the page jumps to top.

I'm not sure how to fix that. I searched about ajaxifying of the registration form - and there is the working decision - I mean that form is working, but how to add billing fields in it?

I tried to paste billing_last_name just for test, but it's wrong.

$user_data = array(
    'user_login' => $new_user_name,
    'user_email' => $new_user_email,
    'user_pass' => $new_user_password,
    'user_nicename' => $user_nice_name,
    'display_name' => $new_user_first_name,
    'billing_last_name'=> $new_user_password,
    'role' => 'customer'
);

In dashboard the customer information is in another table, not in the main user table, maybe I need to use another array? Or all fields from user section in dashboard are from $user_data table?

I'm not lazy to paste all 13 fields to that function, I prefer that, not plugins. I just need 1 example with one billing field, how to do it right?

Or that is a bad idea and there is a better one, that simply can make the work of submit button more correct? What's the best decision without using plugins?

0

There are 0 best solutions below