1

このために 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' );

現在、管理者が詳細を確認できるように、ユーザーメニューのユーザー編集ページにこれら 2 つの詳細 (生年月日と携帯電話番号) を追加/表示しようとしています。場所の画像を添付します

ここに画像の説明を入力

しかし、このページのデータを読み取ることができません。


私は次のフックを使用しようとしています:

add_action( 'edit_user_profile', 'print_custom_fileds_in_edit_user', 30 ); 

何かアドバイスはありますか?

4

1 に答える 1