javascript - 保存在 Wordpress 用户配置文件中的新字段
问题描述
我在使用 Wocommerce 发送购买时创建的所有用户的个人资料中创建了一个额外的字段:
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
<h3>Extra profile information</h3>
<table class="form-table">
<tr>
<th><label for="DNI"></label></th>
<td>
<input type="text" name="dni" id="dni" value="<?php echo esc_attr( get_the_author_meta( 'dni', $user->ID ) ); ?>" class="regular-text" /><br/>
<span class="description">DNI</span>
</td>
</tr>
</table>
<?php }
要保存它:
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) {
return false;
}
update_user_meta( $user_id, 'dni', $_POST['dni'] );
}
我还使用插件“结帐字段编辑器”在 Wocommerce 购买表单中创建了一个额外的字段。
现在我想链接这些字段,并且在进行购买时输入的值保存在配置文件中创建的值中。
可能吗?
解决方案
推荐阅读
- android - inappwebvew 中的 Flutter 不保留会话
- algorithm - 矩阵中两个单元格之间的最短路径
- xbrl - 无法打开 Arelle 菜单视图以使用 SEC 的 EdgarRenderer
- visual-studio - VS 2019 可以使用现有的 Python 虚拟环境吗?
- azure - 我是否必须将 Azure SignalR 用于部署到 Azure 的 SignalR 服务?
- python - 在 Python 中读取多个大文件时出现内存泄漏
- react-native - keyboardType="number-pad" 在 Android 中仍然显示小数点
- java - 当我使用 eqlipse 在 tomcat 服务器中运行我的 jsp 动态 Web 项目时发现此错误
- arrays - 使用 WHERE 条件时,Postgres 查询以双精度 [] 打乱值
- colors - 获得指定颜色的最对比色的公式是什么?