adding custom File field to Woocommerce dokan plugin

Viewed 105

I’m trying to add an extra field on dokan registration for vendors to upload an identification document.. i found the code specified for adding an extra field to the form but it is for a "text" input type… i changed the input type from "text" to "file"

<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>

and that worked… but the code to save and display the field content on the user backend doesn’t show the image just the same upload box

// save id verification field I also used below code to show in admin side but image not shown not move to folders

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'] );
}

0 Answers
Related