I am creating a Woocommerce site where I wanna give vendors to upload products from their front end. But I stuck on a point where I am trying to add woocommerce downloadable products.
Here is my current code:
//Let's upload the download file Zip
$zipattachment_id = upload_music_files($music_ID, $musicZip); //This is my custom function which returns attachment id after file upload
$download_file_name = $musicZip['name'];
$download_file_url = wp_get_attachment_url($zipattachment_id);
$md5_download_num = md5( $download_file_url );
//creating array of download product
$downloadable_file[$md5_download_num] = array(
'id' => $md5_download_num,
'name' => $download_file_name,
'file' => $download_file_url,
'previous_hash' => ''
);
$downloadMusic = serialize($downloadable_file);
// adding downloadble file with the new array
add_post_meta( $music_ID, '_downloadable_files', $downloadMusic );
But when I open the product edit from backend no downloadable files exits.
Here is example return of the seriallized array :
a:1:{s:32:"22618d7f028803f57f98ab6b21277387";a:4:{s:2:"id";s:32:"22618d7f028803f57f98ab6b21277387";s:4:"name";s:5:"1.zip";s:4:"file";s:71:"http://mydomain/wp-content/uploads/2017/12/5a2e22cecaca6_1.zip";s:13:"previous_hash";s:0:"";}}
I am working with the latest version of woocommerce, can anybody suggest me what I am doing wrong and what can be the right way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…