if($_FILES){
$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);

if(!empty($files)){
update_post_meta($order->ID,_files,$files));
}
// 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.

Your Answer
Sign In
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.