Я хочу, чтобы мое настраиваемое поле, которое было добавлено на странице администратора woocommerce "Новый заказ", было установлено / сохранено на странице "user-edit. php". Поле отображается, и после отправки также отображается дата ввода.
Весь этот код находится в моих функциях. php файл.
Это мой код для отображения поля в woocommerce страница "Новый заказ":
add_filter('woocommerce_admin_billing_fields', 'add_woocommerce_admin_billing_fields');
function add_woocommerce_admin_billing_fields($billing_fields) {
// Remove unnecessary fields
unset($billing_fields['country']);
unset($billing_fields['company']);
unset($billing_fields['address_1']);
unset($billing_fields['address_2']);
unset($billing_fields['city']);
unset($billing_fields['postcode']);
unset($billing_fields['state']);
// Add custom field
$billing_fields['birth_date'] = array(
'type' => 'date',
'label' => __('Geboortedatum'),
'class' => 'form-field-wide',
'priority' => 25,
'required' => true,
'clear' => true,
);
return $billing_fields;
}
С этим кодом поле будет отображаться на странице "edit-user. php":
add_action( 'edit_user_profile', 'custom_user_profile_fields' );
add_action( 'show_user_profile', 'custom_user_profile_fields' );
function custom_user_profile_fields($user) { ?>
<table class="form-table" role="presentation">
<tr class="form-field form-required">
<th scope="row">
<label for="billing_birth_date">
<?php _e('Geboortedatum');
if (empty(esc_attr( get_the_author_meta( 'billing_birth_date', $user->ID ) ))) { ?>
<span class="description"><?php _e('(required)') ?></span>
<?php }?>
</label>
</th>
<td>
<?php if (empty(esc_attr( get_the_author_meta( 'billing_birth_date', $user->ID ) ))) { ?>
<input type="date" class="regular-text" id="birthday" name="billing_birth_date" value="<?php echo esc_attr( get_the_author_meta( 'billing_birth_date', $user->ID ) ); ?>"/>
<?php }
else { ?>
<input type="date" class="regular-text" id="birthday" name="billing_birth_date" value="<?php echo esc_attr( get_the_author_meta( 'billing_birth_date', $user->ID ) ); ?>" disabled="disabled" />
<span class="description">Geboortedatums kunnen niet worden veranderd.</span>
<?php }?>
</td>
</tr>
</table>
<?php
}
И с этим кодом настраиваемое поле на странице «edit-user. php» сохраняется:
function userMetaBirthdaySave($userId) {
if(empty(esc_attr( get_the_author_meta( 'billing_birth_date', $userId ) ))) {
if (!current_user_can('edit_user', $userId)) {
return;
}
update_user_meta($userId, 'billing_birth_date', $_POST['billing_birth_date']);
}
}
add_action('personal_options_update', 'userMetaBirthdaySave');
add_action('edit_user_profile_update', 'userMetaBirthdaySave');
Так как же значение настраиваемого поля на странице «Новый заказ» может быть установлено в настраиваемое поле на странице редактирования пользователя?