【发布时间】:2017-05-06 19:07:11
【问题描述】:
所以我已经很接近了,但这里肯定有一个错误。 我正在做的是我在 WP wooCommerce 安装中添加了 3 个自定义字段。我已经通过 hooks 和 woo 模板添加到注册和我的帐户页面。我可以从他们的个人资料区域/前端成功地以用户身份更新。 我坚持的是让编辑用户管理表单更新这些字段。我可以显示这些字段,但它们只是没有更新。
寻求想法和帮助。我错过了什么?提前致谢。
这是我在子主题functions.php中的代码 - ADMIN EDIT USER
function sbb_custom_user_profile_fields($user) {
?>
<legend><h4>Reseller Info</h4></legend>
<table class="form-table">
<tr>
<th>
<label for="ssb_reseller_tax_id"><?php _e('Resseller Tax ID'); ?></label>
</th>
<td>
<input type="text" name="sbb_reseller_tax_id" id="sbb_reseller_tax_id"
value="<?php echo esc_attr( get_the_author_meta( 'reseller_tax_id', $user->ID
) ); ?>" class="regular-text" />
</td>
</tr>
<tr>
<th>
<label for="sbb_title"><?php _e('Title'); ?></label>
</th>
<td>
<input type="text" name="sbb_title" id="sbb_title" value="<?php echo esc_attr( get_the_author_meta( 'title', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
<tr>
<th>
<label for="sbb_fax"><?php _e('Fax'); ?></label>
</th>
<td>
<input type="text" name="sbb_fax" id="sbb_fax" value="<?php echo esc_attr( get_the_author_meta( 'fax', $user->ID ) ); ?>" class="regular-text" />
</td>
</tr>
</table>
<?php
update_user_meta( get_the_author_meta( $user->ID ), 'reseller_tax_id', htmlentities( $_POST[ 'reseller_tax_id' ] ) );
update_user_meta( get_the_author_meta( $user->ID ), 'fax', htmlentities( $_POST[ 'fax' ] ) );
update_user_meta( get_the_author_meta( $user->ID ), 'title', htmlentities( $_POST[ 'title' ] ) );
}
add_action('show_user_profile', 'sbb_custom_user_profile_fields');
add_action('edit_user_profile', 'sbb_custom_user_profile_fields');
add_action('edit_user_profile_update', 'sbb_custom_user_profile_fields' );
【问题讨论】:
标签: php wordpress woocommerce edit