使用Woocommerce更新Wordpress上的用户信息吗? [英] Updating User information on Wordpress with Woocommerce?

查看:112
本文介绍了使用Woocommerce更新Wordpress上的用户信息吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在使用Wordpress和2个插件
http:// www.wpexplorer.com/wordpress-user-contact-fields/

Woocommerce

I'm currently using Wordpress and 2 plugins http://www.wpexplorer.com/wordpress-user-contact-fields/ and Woocommerce

我正在使用woocommerce称为form-edit-account.php,但是它允许用户编辑他的信息。

I'm using an endpoint from woocommerce called form-edit-account.php, it lets the user edit his information, however.

问题是,每次我按update时,所有内容都会正确更新,但是电话号码。我在小动脉之间添加了所有内容。

The problem is, everytime I press update, everything gets updated properly but the phone number. I added everything inbetween the arterisks.

<?php wc_print_notices(); ?>

<form action="" method="post">

    <p class="form-row form-row-first">
        <label for="account_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="account_first_name" id="account_first_name" value="<?php echo esc_attr( $user->first_name ); ?>" />
    </p>
    <p class="form-row form-row-last">
        <label for="account_last_name"><?php _e( 'Last name', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="account_last_name" id="account_last_name" value="<?php echo esc_attr( $user->last_name ); ?>" />
    </p>
    <p class="form-row form-row-wide">
        <label for="account_email"><?php _e( 'Email address', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="email" class="input-text" name="account_email" id="account_email" value="<?php echo esc_attr( $user->user_email ); ?>" />
    </p>
    <p class="form-row form-row-first">
        <label for="password_1"><?php _e( 'Password (leave blank to leave unchanged)', 'woocommerce' ); ?></label>
        <input type="password" class="input-text" name="password_1" id="password_1" />
    </p>
    <p class="form-row form-row-last">
        <label for="password_2"><?php _e( 'Confirm new password', 'woocommerce' ); ?></label>
        <input type="password" class="input-text" name="password_2" id="password_2" />
    </p>
    *****************
    <p class="form-row form-row-wide">
        <label for="account_phone"><?php _e( 'Phone', 'woocommerce' ); ?> </label>
        <input type="text" class="input-text" name="phone" id="phone" value="<?php echo esc_attr( $user->phone ); ?>" />
    </p>
    *****************
    <div class="clear"></div>

    <p><input type="submit" class="button" name="save_account_details" value="<?php _e( 'Save changes', 'woocommerce' ); ?>" /></p>

    <?php wp_nonce_field( 'save_account_details' ); ?>
    <input type="hidden" name="action" value="save_account_details" />
</form>

是否仍然可以继续使用woocommerce更新此自定义信息?抱歉,我对woocommerce和基于用户的网站都是陌生的。

Is there anyway to keep using woocommerce to update this custom info? Sorry I'm new both to woocommerce and to user based websites.

谢谢

推荐答案

@doublesharp

@doublesharp

您的代码中有一些错误。

There are a few errors in your code.

update_usermeta

实际上是

update_user_meta

add_action("save_account_details",...

应该是

add_action( 'woocommerce_save_account_details',...

因此完整代码应为

function save_additional_account_details( $user_ID ){
    $phone = ! empty( $_POST['phone'] ) ? wc_clean( $_POST['phone'] ) : '';
    update_user_meta( $user_ID, 'phone', $phone );
}
add_action( 'woocommerce_save_account_details', 'save_additional_account_details' );

给我一​​点试错,但我给了我正确的路,谢谢!

Took me a little trial&error to figure this out, but you gave me a right track, thanks!

干杯,亚历克斯

Cheers, Alex

这篇关于使用Woocommerce更新Wordpress上的用户信息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆