Добавление новых полей для заполнения в файле «wp-admin/user-edit.php»
Нужно добавить поле для которое можно редактировать в личном кабинете пользователя.
Использовал следущee
"wp-admin/user-edit.php"
<tr class="user-phone-number-wrap"> <th><label for="account_phone_number"><?php _e( 'Phone number' ); ?></label></th> <td><input type="text" name="account_phone_number" id="account_phone_number" value="<?php echo esc_attr( $profile_user->phone_number ); ?>" class="regular-text" /></td> </tr>
"
Здесь добавил новое значение. В моём случае "account_phone_number"
"/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php"
$account_first_name = ! empty( $_POST['account_first_name'] ) ? wc_clean( wp_unslash( $_POST['account_first_name'] ) ) : ''; $account_last_name = ! empty( $_POST['account_last_name'] ) ? wc_clean( wp_unslash( $_POST['account_last_name'] ) ) : ''; $account_display_name = ! empty( $_POST['account_display_name'] ) ? wc_clean( wp_unslash( $_POST['account_display_name'] ) ) : ''; $account_email = ! empty( $_POST['account_email'] ) ? wc_clean( wp_unslash( $_POST['account_email'] ) ) : ''; $account_phone_number = ! empty( $_POST['account_phone_number'] ) ? wc_clean( wp_unslash( $POST['account_phone_number'] ) ) : ''; $pass_cur = ! empty( $_POST['password_current'] ) ? $_POST['password_current'] : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash $pass1 = ! empty( $_POST['password_1'] ) ? $_POST['password_1'] : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash $pass2 = ! empty( $_POST['password_2'] ) ? $_POST['password_2'] : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash $save_pass = true; // Current user data. $current_user = get_user_by( 'id', $user_id ); $current_first_name = $current_user->first_name; $current_last_name = $current_user->last_name; $current_email = $current_user->user_email; // New user data. $user = new stdClass(); $user->ID = $user_id; $user->first_name = $account_first_name; $user->last_name = $account_last_name; $user->display_name = $account_display_name; $user->phone_number = $account_phone_number;
И так же добавил соответствующее поле в личный кабинет пользователя.
"woocommerce/myaccount/form-edit-account.php"
<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> <label for="phone_number"><?php esc_html_e( 'Номер телефону', 'woocommerce' ); ?></label> <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="phone_number" id="phone_number" value="<?php echo esc_attr( $user->phone_number ); ?>" /> <span><em><?php esc_html_e( 'Це ваш номер телефону, який буде використовуватись для оформлення ваших замовлень', 'woocommerce' ); ?></em></span> </p> <div class="clear"></div>
Новые поля, что в админке, что в кабинете пользователя появились, но при попытке их редактировать, после сохранения новых введённых данных, они не сохраняются, а остаются пустыми. Подскажите пожалуйста - что я делаю не так, или что не доделал, т.к.
Если есть ошибки в моих действиях, то тоже укажите на них.
mi13
Спасибо, помогло.
how-to-add-custom-fields-to-user-profile-page-in-wordpress