简体   繁体   中英

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.¨

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM