Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce Edit Account throwing 'display name is a required field' error

I'm having an issue with WooCommerce edit account page. When submitting the form the error message 'display name is a required field' displays. I've attempted adding a field both

input type="text" and

<select name="display_name" id="display_name" >
    <option selected="selected"><?php echo esc_attr( $user->display_name ); ?></option>
</select>

but no luck trying to add the field. I've also attempted making the field not required but I'm unsure how to do they with the latest version of WooCommerce.

like image 699
Nathan Shanahan Avatar asked May 31 '18 05:05

Nathan Shanahan


2 Answers

to make it not required, use this:

add_filter('woocommerce_save_account_details_required_fields', 'wc_save_account_details_required_fields' );
function wc_save_account_details_required_fields( $required_fields ){
    unset( $required_fields['account_display_name'] );
    return $required_fields;
}

If you wanted it required, to make the field for it, you need to give it a name attribute 'account_display_name'

like image 171
Reigel Avatar answered Sep 28 '22 11:09

Reigel


You can use woocommerce shortcode [woocommerce_my_account] on your page which has current_user in args array which is automatically set using get_user_by( ‘id’, get_current_user_id() ) Reference: woocommerce documentation

Try the following code. I think you should use input instead of select

<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="account_display_name" id="account_display_name" value="<?php echo esc_attr($user->display_name);?>">
like image 28
Nawaz Ghori Avatar answered Sep 28 '22 11:09

Nawaz Ghori