久久久久久久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)
主站蜘蛛池模板: 欧美在线一区二区三区 | 中文av电影 | 在线一区视频 | 久久免费精品视频 | 久久久久久免费毛片精品 | 国产精品美女久久久久 | 国产精品高清在线 | 久草新在线 | 日韩欧美中文 | 产真a观专区 | 欧美国产日韩在线观看 | 免费一区 | 精品国产一区二区在线 | 日韩综合网 | 麻豆精品一区二区三区在线观看 | 91视频网址| 中文字幕在线一区 | 欧美自拍网站 | 伦理二区 | 中文字幕视频在线观看 | 日韩中文字幕 | 亚洲精品亚洲人成人网 | 欧美精品一二区 | 久产久精国产品 | 色婷婷综合久久久中字幕精品久久 | 精品视频一区二区三区在线观看 | 精久久久 | 欧美在线a| 欧美精品在线一区二区三区 | 久久国产精品视频 | 91精品国产综合久久精品 | 国产激情91久久精品导航 | 久久亚洲一区 | 亚洲国产成人av好男人在线观看 | 91精品国产综合久久婷婷香蕉 | 欧美日韩中文在线 | 精品一区二区三区四区 | 日韩精品在线观看视频 | 一区二区精品电影 | 日韩精品一区二区三区在线观看 | 日韩欧美一区二区三区四区 |