自定义注册字段未显示在用户信息中

时间:2017-05-11 作者:Piyush Kumar

我需要在我的woocommerce网站的注册表中添加一个电话号码字段。

我使用了以下代码

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


function wooc_validate_extra_register_fields( $username, $email, 
$validation_errors ) {
  if ( isset( $_POST[\'billing_phone\'] ) && empty( $_POST[\'billing_phone\'] ) ) 
  {
    $validation_errors->add( \'billing_phone_error\', __( \'<strong>Error</strong>: 
    Phone is required!.\', \'woocommerce\' ) );
  }
}
add_action( \'woocommerce_register_post\',\'wooc_validate_extra_register_fields\', 10, 3 );


function wooc_save_extra_register_fields( $customer_id ) {
  if ( isset( $_POST[\'billing_phone\'] ) ) {
  // WooCommerce billing phone
    update_user_meta( $customer_id, \'billing_phone\', sanitize_text_field( 
    $_POST[\'billing_phone\'] ) );
  }
}
add_action( \'woocommerce_created_customer\',\'wooc_save_extra_register_fields\' );
代码工作正常,新字段出现在注册表中。但是,该电话号码未保存在管理面板的用户中。如何使其显示在那里?

谢谢

1 个回复
SO网友:TJ152

尝试WC AFOUR, 我有一个类似的要求,我需要添加名称和;WooCommerce注册表的地址字段,它正好满足了我的需要。

结束

相关推荐

如何写入wp-USERS表

我正在尝试修改一个登录插件,让新用户在注册时输入要在网站上显示的显示名称。我知道显示名称位于数据库的wp users表中,但无法对其进行写入。Edit<?php function wps_pro_login_registration_errors( $errors ) { if ( empty( $_POST[\'first_name\'] ) ) $errors->add( \'empty_first_name\', \'<st