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.
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'
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);?>">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With