php - 将自定义文件字段添加到 Woocommerce dokan 插件
问题描述
我正在尝试在 dokan 注册上添加一个额外字段,供供应商上传身份证明文件。我找到了为表单添加额外字段而指定的代码,但它是用于“文本”输入类型……我更改了输入类型从“文本”到“文件”
<p class="form-row form-group form-row-wide">
<label for="veri-file"><?php esc_html_e( 'Upload Verification ID', 'dokan-custom-codes' ); ?><span class="required">*</span></label>
<input type="file" class="verifile" name="veri_file" id="veri_file" accept="image/png, image/jpeg" value="upload"<?php if ( ! empty( $postdata['veri_file'] ) ) echo esc_attr($postdata['veri_file']); ?>" required="required" />
</p>
并且有效......但是在用户后端保存和显示字段内容的代码并没有显示图像只是同一个上传框
// 保存 id 验证字段我还使用下面的代码在管理端显示,但图像未显示不会移动到文件夹
function dokan_custom_seller_registration_required_fields( $required_fields ) {
$required_fields['veri_file'] = __( 'Please upload a valid means of Identification', 'dokan-custom' );
return $required_fields;
};
add_filter( 'dokan_seller_registration_required_fields', 'dokan_custom_seller_registration_required_fields' );
function dokan_custom_new_seller_created( $vendor_id, $dokan_settings ) {
$post_data = wp_unslash( $_POST );
$veri_file = $post_data['veri_file'];
update_user_meta( $vendor_id, 'dokan_custom_veri_file', $veri_file );
}
add_action( 'dokan_new_seller_created', 'dokan_custom_new_seller_created', 10, 2 );
/* Add custom profile fields (call in theme : echo $curauth->fieldname;) */
add_action( 'dokan_seller_meta_fields', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<?php if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
if ( ! user_can( $user, 'dokandar' ) ) {
return;
}
$gst = get_user_meta( $user->ID, 'dokan_custom_veri_file', true );
?>
<tr>
<th><?php esc_html_e( 'Upload Verification ID', 'dokan-lite' ); ?></th>
<td>
<input type="file" name="veri_file" class="verifile" value="<?php echo esc_attr($gst); ?>"/>
<img src=".$gst." height=200 width=300 />
</td>
</tr>
echo "<img src=".$gst." height=200 width=300 />";
<?php
}
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
update_usermeta( $user_id, 'dokan_custom_veri_file', $_POST['veri_file'] );
}
解决方案
推荐阅读
- buffer-overflow - Exploiting VulnServer TRUN 命令中的“/.:/”
- google-maps - 使用 google maps api 通过点击 Ionic 在地图上绘制折线
- java - Java 字符串到字节数组,丢失特殊字符 §
- php - Laravel RouteServiceProvider 地图功能未调用
- android - 自动完成不适用于谷歌地图。尝试在“搜索框”中添加地点名称时
- string - 如何在 SQLite3 命令行中将字符串拆分为新列?
- java - Android 中新的 PDF 页面创建产生的页面比预期的要多
- java - 如何解决 Android 运行时预期“无法获取文件列表 xyz.geshkii.weather”?
- r - ggplot中的百分比而不是计数
- python - 使用 Codeforces API 通过 discord bot (discord.py) 获取有关用户在 CF 问题上的所有 AC 的信息 - python 中的 json 文件处理错误