【发布时间】:2015-02-19 09:19:21
【问题描述】:
相信你的日子过得很充实。我需要从前端创建一个可下载的 woocommerce 产品。我已经能够创建链接以发布产品并将音频文件添加为附件,但我需要在付款后使此附件可下载,就像您从仪表板发布可下载的 woocommerce 产品时一样。我已经可以在仪表板中看到我的产品,但我必须手动检查可下载并从仪表板添加文件。请我需要有关如何使从前端发布的产品可自动下载的帮助。 感谢人们一直以来。 下面是我的代码 sn-p 。
// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title' => $title,
'post_content' => $description,
'post_category' => array($_POST['cat']),
'tags_input' => array($tags),
'post_status' => 'draft',
'post_type' => 'product', //'post',page' or use a custom post type if you want to
'rating' => $myrating
);
//SAVE THE POST
$pid = wp_insert_post($new_post);
//KEEPS OUR COMMA SEPARATED TAGS AS INDIVIDUAL
wp_set_post_tags($pid, $_POST['post_tags']);
//REDIRECT TO THE NEW POST ON SAVE
$link = get_permalink( $pid );
wp_redirect( $link );
//ADD OUR CUSTOM FIELDS
add_post_meta($pid, 'rating', $myrating, true);
//INSERT OUR MEDIA ATTACHMENTS
if ($_FILES) {
foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$pid);
// $newupload returns the attachment id of the file that
}
} // END THE IF STATEMENT FOR FILES
【问题讨论】:
-
这段代码在哪个文件中?
-
您好,代码是从我创建的自定义模板页面中提取的。
-
所以我猜你需要在有人购买产品时显示可下载的文件?
标签: php wordpress upload woocommerce attachment