Home Woocommerce add downloadable files by PHP
Reply: 0

Woocommerce add downloadable files by PHP

mathvc_
1#
mathvc_ Published in 2018-02-14 11:42:57Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312785 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO