$attach_id = media_handle_upload( ‘update_pub’, $post_id );
$file_name = ‘Order completed Files’;
$file_url = wp_get_attachment_url($attach_id);
$md5_num = md5( $file_url );

// Inserting new file in downloadable files
$files[$md5_num] = array(
‘name’ => $file_name,
‘file’ => $file_url

// Updating database with the new array
$order = new WC_Order($order_id);

// Displaying a success notice
echo ‘The image has been uploaded successfully!’;

You can use this code on order complete with woocommerce_order_status_completed hook.

Please login or Register to submit your answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.