我为此定制了 WooCommerce 的用户注册流程,我添加了一些额外的字段,例如出生日期和手机号码。
我添加了这样的表单元素:
function my_extra_register_fields() {?>
<p class="form-row form-row-wide">
<label for="reg_dob"><?php _e( 'Date of Birth', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="input-text" name="reg_customer_dob" id="reg_customer_dob" />
</p>
<p class="form-row form-row-wide">
<label for="reg_billing_phone"><?php _e( 'Mobile', 'woocommerce' ); ?><span class="required">*</span></label>
<input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" />
</p>
<div class="clear"></div>
<?php
}
add_action( 'woocommerce_register_form', 'my_extra_register_fields' );
我正在存储这样的数据 -
function wooc_save_extra_register_fields( $customer_id ) {
if ( isset( $_POST['billing_phone'] ) ) {
// Phone input filed which is used in WooCommerce
update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );
}
if ( isset( $_POST['reg_customer_dob'] ) ) {
// Phone input filed which is used in WooCommerce
update_user_meta( $customer_id, 'customer_dob', sanitize_text_field( $_POST['reg_customer_dob'] ) );
}
}
add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
现在我正在尝试在用户菜单的编辑用户页面中添加/显示这两个详细信息(出生日期和手机号码),以便管理员可以查看详细信息。附上位置图片
但我无法读取此页面中的数据。
我正在尝试使用以下钩子:
add_action( 'edit_user_profile', 'print_custom_fileds_in_edit_user', 30 );
有什么建议吗?