简体   繁体   English

Wordpress Woocommerce 在我的帐户页面中添加自定义表单

[英]Wordpress Woocommerce Add custom form in my account page

I need to create a custom form in a new tab in woocommerce my account page.¨我需要在 woocommerce 我的帐户页面的新选项卡中创建一个自定义表单。

I need to save data and output them to the user我需要保存数据并将它们输出给用户

What I've tried:我试过的:

add_action( 'init', 'misha_add_endpoint' );
function misha_add_endpoint() {
    add_rewrite_endpoint( 'log-history', EP_PAGES );

}
add_action( 'woocommerce_account_log-history_endpoint', 'misha_my_account_endpoint_content' );
function misha_my_account_endpoint_content() {
 get_current_user_id()
    echo '<h3>User settings prize wheel</h3>';

    $user = wp_get_current_user();

    echo '
<form class="woocommerce-EditAccountForm edit-account" action="" method="post">
    <p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
        <label for="account_display_name">Steam ID&nbsp;<span class="required">*</span></label>
        <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="steam_id" id="account_display_name" value="'.esc_attr( $user->steam_id ).'"> <span><em>Vaše Steam ID, místo kam se budou posílat výherní item. </em></span>
    </p>
    <div class="clear"></div>

    <p>
        <button type="submit" class="woocommerce-Button button" name="save_prize_wheel" value="Uložit změny">Uložit změny</button>
        <input type="hidden" name="action" value="save_prize_wheel">
    </p>

    </form>
    ';

}

add_action( 'woocommerce_save_prize_wheel', 'save_favorite_color_account_details', 12, 1 );

function save_favorite_color_account_details( $user_id ) {
    // For Favorite color
    if( isset( $_POST['steam_id'] ) )
        update_user_meta( $user_id, 'steam_id', sanitize_text_field( $_POST['steam_id'] ) );
}

The data did not save.数据没有保存。

你在这里想念半科林get_current_user_id()应该是get_current_user_id();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WordPress woocommerce清空我的帐户+汽车页面 - Wordpress woocommerce empty my account + car page WooCommerce新账户页面添加自定义字段 - Add custom fields to WooCommerce new account Page 在 Woocommerce 编辑帐户页面中添加自定义字段 - Add a custom field in Woocommerce Edit Account page 如何在“我的帐户”页面的“WooCommerce 我的订单”列表中添加自定义数据作为新列? - How to Add Custom Data as a New Column in the WooCommerce My Orders list in My Account page? 将高级自定义字段添加到 Dokan 上的现有表单 - 添加产品和编辑产品页面 (WordPress/WooCommerce) - Add Advanced Custom Field to existing form on Dokan- Add product & edit product page (WordPress/WooCommerce) 如何在 WooCommerce “我的帐户”页面上对自定义字段重新排序或添加优先级 - How do I re-order or add priority to a custom field on WooCommerce “My Account” page WooCommerce 我的帐户页面自定义菜单项与自定义链接 - WooCommerce My Account page custom menu item with custom link Woocommerce 我的帐户自定义页面 - 找不到页面 404(永久链接问题) - Woocommerce my account custom page - page not found 404 (permalinks problem) 从自定义 WooCommerce 我的帐户选项卡保存表单数据 - Saving form data from a custom WooCommerce My Account tab 从“我的帐户”自定义选项卡提交 woocommerce 订单跟踪表 - Submit woocommerce order tracking form from My Account custom tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM