I’m currently using WordPress and 2 plugins
http://www.wpexplorer.com/wordpress-user-contact-fields/
and
Woocommerce
I’m using an endpoint from woocommerce called form-edit-account.php, it lets the user edit his information, however.
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>
Is there anyway to keep using woocommerce to update this custom info? Sorry I’m new both to woocommerce and to user based websites.
Thanks
@doublesharp
There are a few errors in your code.
is in fact
and
should be
so the full code should be
Took me a little trial&error to figure this out, but you gave me a right track, thanks!
Cheers,
Alex
The
save_account_details()
function handles the form processing forform-edit-account.php
. Once the default save is completed without errors, there is an action hook calledwoocommerce_save_account_details
that you can use to save further information – it takes only the user ID as an argument, but the rest of the info is available in the$_POST
.You also have a couple of issues with the code you added to the page:
for
attribute of the<label>
tag has to match thename
of the<input>
tag, so “phone”_e( 'Phone', 'woocommerce' );
unless “Phone” exists in the WooCommerce translationsget_usermeta()
.Your additional code should look like the following.