doudeng9425 2018-09-25 16:52
浏览 72
已采纳

Woocommerce添加下载文件/产品进行订购

Standard downloadable products are not suitable. It is necessary to generate the file after the creation and payment of the order and provide access to the buyer. More than a day looking for information on this topic, found something similar, but not that. It is necessary that the file is generated and attached to the order immediately after payment (it can also be free of charge) or, after payment, the order was able to process, there was an interception with the help of a hook woocommerce_order_status_processing, the file was generated, the file was attached to the order, and the message was sent to the mail. I tried to simply add a file to the order, but it is not added:

$pd_object = new WC_Product_Download();
$pd_object->set_id($md5_num);
$pd_object->set_name($file_name);
$pd_object->set_file($file_url);
update_post_meta($order_id,'_files', $pd_object);

I also tried to generate a new product on the move, put the uploaded file into it, and then add this product to the order, it is added but without a file:

$pd_object = new WC_Product_Download();
$pd_object->set_id($md5_num);
$pd_object->set_name($file_name);
$pd_object->set_file($file_url);
$order_product = new WC_Product();
$order_product -> set_name('ORDER'.$order_id);
$order_product -> set_price(0);
$order_product -> set_virtual(true);
$order_product -> set_downloadable(true);
$downloads = $order_product->get_downloads();
$downloads[$md5_num] = $pd_object;
$order_product -> set_downloads($pd_object);
$order -> add_product($order_product,1);

I want the file to be available to the buyer as if using standard downloadable products: Admin panel Buyer Profile

  • 写回答

1条回答 默认 最新

  • doudu5029 2018-09-29 16:15
    关注

    found the answer himself.

    wc_downloadable_file_permission($pd_object->get_id(),$order_product->get_id(),$order);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?