Este snippet te permite agregar un campo personalizado definido previamente (user meta) al formulario de «Editar Cuenta» de WooCommerce.
/*
Añadir el campo personalizado a los campos del perfil de WooCommerce
*/
add_action( 'woocommerce_edit_account_form', 'elgeneralista_snippet_add_custom_field_to_account_form' );
function elgeneralista_snippet_add_custom_field_to_account_form() {
$user = wp_get_current_user();
echo '<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">';
echo '<label for="id_del_campo">'._e( 'Valor de campo', 'woocommerce' ).'</label>';
echo'<input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="id_del_campo" id="id_del_campo" value="'.esc_attr( $user->id_del_campo).'" placeholder="Valor de campo" />';
echo '</p>';
echo '<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide"> </p>';
}
/*
Guardar valor de campo personalizado del perfil de WooCommerce
*/
add_action( 'woocommerce_save_account_details', 'elgeneralista_snippet_save_account_data', 12, 1 );
function elgeneralista_snippet_save_account_data( $user_id ) {
if( isset( $_POST['id_del_campo'] ) )
update_user_meta( $user_id, 'id_del_campo', sanitize_text_field( $_POST['id_del_campo'] ) );
}