首页 > 解决方案 > 在注册表单中添加的额外字段将保存在 wp_users 表中,而不是 wp_usermeta 表(WooCommerce)

问题描述

我在注册表中添加了额外的字段。代码如下:

function wooc_extra_register_fields() {
       ?>
       <p class="form-row form-row-first">
       <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>
       <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
       </p>
       <p class="form-row form-row-last">
       <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span class="required">*</span></label>
       <input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
       </p>
       <div class="clear"></div>
       <p class="form-row form-row-wide">
       <label for="reg_billing_phone"><?php _e( 'Mobile Phone No.', 'woocommerce' ); ?><span class="required">*</span></label>
       <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php esc_attr_e( $_POST['billing_phone'] ); ?>" />
       </p>
       <?php
}
add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );

现在我希望这些字段在 wp-user 数据库中可见,以便可以在一个地方看到所有用户数据,而不是切换到用户元数据来查看额外的字段数据。有什么办法吗?

如果我必须添加一个额外的数据库,那该怎么办?

标签: phpwordpresswoocommercehook-woocommerce

解决方案


推荐阅读