Provides edit display name in my-account page (#17606)

This commit is contained in:
Arif Widianto 2017-11-22 15:20:49 +07:00
parent 16152bfcf0
commit 0b42515c93
3 changed files with 17 additions and 3 deletions

View File

@ -195,6 +195,7 @@ class WC_Form_Handler {
$account_first_name = ! empty( $_POST['account_first_name'] ) ? wc_clean( $_POST['account_first_name'] ) : '';
$account_last_name = ! empty( $_POST['account_last_name'] ) ? wc_clean( $_POST['account_last_name'] ) : '';
$account_display_name = ! empty( $_POST['account_display_name'] ) ? wc_clean( $_POST['account_display_name'] ) : '';
$account_email = ! empty( $_POST['account_email'] ) ? wc_clean( $_POST['account_email'] ) : '';
$pass_cur = ! empty( $_POST['password_current'] ) ? $_POST['password_current'] : '';
$pass1 = ! empty( $_POST['password_1'] ) ? $_POST['password_1'] : '';
@ -205,12 +206,18 @@ class WC_Form_Handler {
$user->last_name = $account_last_name;
// Prevent emails being displayed, or leave alone.
$user->display_name = is_email( $current_user->display_name ) ? $user->first_name : $current_user->display_name;
$user->display_name = is_email( $current_user->display_name ) ? sprintf( __( '%1$s %2$s', 'display name', 'woocommerce' ), $user->first_name, $user->last_name ) : $account_display_name;
// Prevent display name change to email
if ( is_email( $user->display_name ) ) {
wc_add_notice( __( 'Display name cannot be changed to email address due to privacy concern.', 'woocommerce' ), 'error' );
$user->display_name = $current_user->display_name;
}
// Handle required fields
$required_fields = apply_filters( 'woocommerce_save_account_details_required_fields', array(
'account_first_name' => __( 'First name', 'woocommerce' ),
'account_last_name' => __( 'Last name', 'woocommerce' ),
'account_display_name' => __( 'Display name publicly as', 'woocommerce' ),
'account_email' => __( 'Email address', 'woocommerce' ),
) );

View File

@ -114,7 +114,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
wp_update_user( apply_filters( 'woocommerce_update_customer_args', array(
'ID' => $customer->get_id(),
'role' => $customer->get_role(),
'display_name' => $customer->get_first_name() . ' ' . $customer->get_last_name(),
'display_name' => sprintf( __( '%1$s %2$s', 'display name', 'woocommerce' ), $customer->get_first_name(), $customer->get_last_name() ),
), $customer ) );
$wp_user = new WP_User( $customer->get_id() );
$customer->set_date_created( $wp_user->user_registered );
@ -218,6 +218,7 @@ class WC_Customer_Data_Store extends WC_Data_Store_WP implements WC_Customer_Dat
'paying_customer' => 'is_paying_customer',
'first_name' => 'first_name',
'last_name' => 'last_name',
'display_name' => 'display_name',
);
foreach ( $meta_key_to_props as $meta_key => $prop ) {

View File

@ -35,6 +35,12 @@ do_action( 'woocommerce_before_edit_account_form' ); ?>
<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="account_last_name" id="account_last_name" value="<?php echo esc_attr( $user->last_name ); ?>" />
</p>
<div class="clear"></div>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="account_display_name"><?php esc_html_e( 'Display name publicly as', 'woocommerce' ); ?> <span class="required">*</span></label>
<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 ); ?>" />
</p>
<div class="clear"></div>
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
<label for="account_email"><?php esc_html_e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>