首页 > 解决方案 > 将自定义文件字段添加到 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'] );
}

标签: phpwordpresswoocommercecustom-wordpress-pagesdokan

解决方案


推荐阅读