久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將生日字段添加到 WooCommerce 我的帳戶和管理員用

Add birthday field to WooCommerce my account and admin user page(將生日字段添加到 WooCommerce 我的帳戶和管理員用戶頁面)
本文介紹了將生日字段添加到 WooCommerce 我的帳戶和管理員用戶頁面的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我在下面添加了代碼.生日字段顯示在我的帳戶頁面和 WP 管理員用戶頁面中,但問題是日期沒有保存.

I have added the code below. The birthday field is showing in my account page and also in WP admin user page as well but the problem is that the date is not saving.

到目前為止我所擁有的

function iconic_get_account_fields() {
return apply_filters( 'iconic_account_fields', array(
    'user_url' => array(
        'type'        => 'date',
        'label'       => __( 'My Birth Date', 'iconic' ),
        'placeholder' => __( 'Date of Birth', 'iconic' ),
        'required'    => true,
    ),
) );
}
/**
* Add fields to registration form and account area.

*/
function iconic_print_user_frontend_fields() {
$fields = iconic_get_account_fields();

foreach ( $fields as $key => $field_args ) {
    woocommerce_form_field( $key, $field_args );
}
}
add_action( 'woocommerce_edit_account_form', 'iconic_print_user_frontend_fields', 10 ); // my account

 /**
 * Add fields to admin area.
 */
function iconic_print_user_admin_fields() {
$fields = iconic_get_account_fields();
?>
<h2><?php _e( 'Additional Information', 'iconic' ); ?></h2>
<table class="form-table" id="iconic-additional-information">
    <tbody>
    <?php foreach ( $fields as $key => $field_args ) { ?>
        <tr>
            <th>
                <label for="<?php echo $key; ?>"><?php echo $field_args['label']; ?></label>
            </th>
            <td>
                <?php $field_args['label'] = false; ?>
                <?php woocommerce_form_field( $key, $field_args ); ?>
            </td>
        </tr>
    <?php } ?>
    </tbody>
 </table>
 <?php
 }


 add_action( 'show_user_profile', 'iconic_print_user_admin_fields', 30 ); // admin: edit profile
 add_action( 'edit_user_profile', 'iconic_print_user_admin_fields', 30 ); // admin: edit other users

<小時>

我部分使用的代碼來自:


I use the code partly from:

終極指南添加自定義 WooCommerce 注冊字段

推薦答案

以下代碼將添加(并保存)一個自定義生日字段到

The following code will add (and save) a custom birthday field to

  • 我的帳戶 - 編輯帳戶
  • 管理員用戶頁面 - 個人資料
// Add field - my account
function action_woocommerce_edit_account_form() {   
    woocommerce_form_field( 'birthday_field', array(
        'type'        => 'date',
        'label'       => __( 'My Birth Date', 'woocommerce' ),
        'placeholder' => __( 'Date of Birth', 'woocommerce' ),
        'required'    => true,
    ), get_user_meta( get_current_user_id(), 'birthday_field', true ));
}
add_action( 'woocommerce_edit_account_form', 'action_woocommerce_edit_account_form' );

// Validate - my account
function action_woocommerce_save_account_details_errors( $args ){
    if ( isset($_POST['birthday_field']) && empty($_POST['birthday_field']) ) {
        $args->add( 'error', __( 'Please provide a birth date', 'woocommerce' ) );
    }
}
add_action( 'woocommerce_save_account_details_errors','action_woocommerce_save_account_details_errors', 10, 1 );

// Save - my account
function action_woocommerce_save_account_details( $user_id ) {  
    if( isset($_POST['birthday_field']) && ! empty($_POST['birthday_field']) ) {
        update_user_meta( $user_id, 'birthday_field', sanitize_text_field($_POST['birthday_field']) );
    }
}
add_action( 'woocommerce_save_account_details', 'action_woocommerce_save_account_details', 10, 1 );

// Add field - admin
function add_user_birtday_field( $user ) {
    ?>
        <h3><?php _e('Birthday','woocommerce' ); ?></h3>
        <table class="form-table">
            <tr>
                <th><label for="birthday_field"><?php _e( 'Date of Birth', 'woocommerce' ); ?></label></th>
                <td><input type="date" name="birthday_field" value="<?php echo esc_attr( get_the_author_meta( 'birthday_field', $user->ID )); ?>" class="regular-text" /></td>
            </tr>
        </table>
        <br />
    <?php
}
add_action( 'show_user_profile', 'add_user_birtday_field', 10, 1 );
add_action( 'edit_user_profile', 'add_user_birtday_field', 10, 1 );

// Save field - admin
function save_user_birtday_field( $user_id ) {
    if( ! empty($_POST['birthday_field']) ) {
        update_user_meta( $user_id, 'birthday_field', sanitize_text_field( $_POST['birthday_field'] ) );
    }
}
add_action( 'personal_options_update', 'save_user_birtday_field', 10, 1 );
add_action( 'edit_user_profile_update', 'save_user_birtday_field', 10, 1 );

這篇關于將生日字段添加到 WooCommerce 我的帳戶和管理員用戶頁面的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 成人精品在线观看 | 国产aa| 91精品久久久久 | 色综合色综合色综合 | 欧美 日韩精品 | 日韩在线视频一区 | 精品久久久久久久久久久久 | 午夜精品一区二区三区在线播放 | 欧美日韩一区精品 | 国产一级视屏 | 国产传媒在线观看 | 成人在线视频免费观看 | 亚洲 欧美 另类 日韩 | 欧美日本一区 | www.99re5.com | 天天插天天狠天天透 | 日韩一区二区三区在线视频 | 国产精品日韩欧美一区二区三区 | 久久aⅴ乱码一区二区三区 亚洲国产成人精品久久久国产成人一区 | 欧美一区二区久久 | 91国内精精品久久久久久婷婷 | 欧美亚洲另类丝袜综合网动图 | 成人在线视频观看 | 自拍偷拍亚洲视频 | 欧美日韩在线播放 | 亚洲精品中文字幕 | 亚洲成人精品一区 | 中文字幕乱码一区二区三区 | 亚洲精品视频播放 | 国产成人综合久久 | 日日摸日日碰夜夜爽亚洲精品蜜乳 | 亚洲免费视频一区二区 | 视频一区中文字幕 | 色狠狠一区 | 日韩三 | 欧美在线视频免费 | 国产天天操 | 国产色婷婷久久99精品91 | 亚洲免费视频在线观看 | 欧美精品久久久久 | 亚洲黄色网址视频 |