How to add & save custom field in My Account Details page in Woocommerce?

add_action( ‘woocommerce_edit_account_form’, ‘my_woocommerce_edit_account_form’ );
add_action( ‘woocommerce_save_account_details’, ‘my_woocommerce_save_account_details’ );

function my_woocommerce_save_account_details( $user_id ) {
update_user_meta( $user_id, ‘dob’, htmlentities( $_POST[ ‘dob’ ] ) );
$user = wp_update_user( array( ‘ID’ => $user_id, ‘user_url’ => esc_url( $_POST[ ‘url’ ] ) ) );
}

function my_woocommerce_edit_account_form() {
$user_id = get_current_user_id();
$user = get_userdata( $user_id );
if ( !$user )
return;
$dob = get_user_meta( $user_id, ‘dob’, true );
$url = $user->user_url;
?>
<fieldset>
<p class=”form-row form-row-thirds”>
<label for=”dob”>Date of Birth:</label>
<input type=”text” id=”datepicker” name=”dob” value=”<?php echo esc_attr( $dob ); ?>” class=”input-text” />
</p>
</fieldset>
<?php
}

Upload image into WordPress media library and get URL

Upload image into WordPress media library and get URL

function upload_image_file( $file = array() ) {

require_once( ABSPATH . ‘wp-admin/includes/admin.php’ );
$file_return = wp_handle_upload( $file, array(‘test_form’ => false ) );
if( isset( $file_return[‘error’] ) || isset( $file_return[‘upload_error_handler’] ) ) {
return false;
} else {
$filename = $file_return[‘file’];
$attachment = array(
‘post_mime_type’ => $file_return[‘type’],
‘post_title’ => preg_replace( ‘/\.[^.]+$/’, ”, basename( $filename ) ),
‘post_content’ => ”,
‘post_status’ => ‘inherit’,
‘guid’ => $file_return[‘url’]
);
$attachment_id = wp_insert_attachment( $attachment, $file_return[‘url’] );
require_once(ABSPATH . ‘wp-admin/includes/image.php’);
$attachment_data = wp_generate_attachment_metadata( $attachment_id, $filename );
wp_update_attachment_metadata( $attachment_id, $attachment_data );
if( 0 < intval( $attachment_id ) ) {
return $attachment_id;
}
}
return false;

}

if( ! empty( $_FILES ) ) {

foreach( $_FILES as $file ) {

if( is_array( $file ) ) {
$attachment_id = upload_image_file( $file );
}

}

}

/*Get atthement URL*/
$logo_url = wp_get_attachment_url( $attachment_id );