I tried to add downloadable files in Woocommerce by PHP by this code:
$pd_object = new WC_Product_Download(); $pd_object->set_id($attachment_id); $pd_object->set_name($attachment['name']); $pd_object->set_file($attachment['file']); $productw = wc_get_product($productw_id); $downloadsw = $productw->get_downloads(); $downloadsw[$attachment_id] = $pd_object; // Set the complete downloads array in the product $productw->set_downloads($downloadsw); $productw->save();
However, the file did not added in downloadable files in edit page of the product. Can anyone help me?
EDIT: I didn't get any error but the files wasn't added in the "downloadable files" when I tried to edit the product page. However, the "_downloadable_files" seems to be correctly edited in my database.phpwordpresswoocommerce