Woocommerce add downloadable files by PHP

mathvc_ Source

I tried to add downloadable files in Woocommerce by PHP by this code:

$pd_object = new WC_Product_Download();


$productw = wc_get_product($productw_id);

$downloadsw = $productw->get_downloads();

$downloadsw[$attachment_id] = $pd_object;

// Set the complete downloads array in the product

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.



comments powered by Disqus