php - 未设置可下载的 Woocommerce 产品内容
问题描述
我正在尝试以编程方式创建 WooCommerce 产品。除了购买后可以下载的实际文件外,一切正常。图像位于正确的文件夹中,代码实际检索它。但是,在执行时,将不会设置可下载文件。我该如何解决这个问题?
public function add_product(){
$product_1 = array(
'post_title' => "Test product",
'post_content' => "This is a temporary description",
'post_status' => 'draft',
'post_type' => "product"
);
$downloadable_file = array(
'id' => '1',
'name' => "Actuall downloadable file",
'file' => "../wp-content/uploads/2021/08/1149.jpg",
);
$downloadPicture = serialize($downloadable_file);
$post_id = wp_insert_post( $product_1 );
update_post_meta( $post_id, '_visibility', 'visible' );
update_post_meta( $post_id, '_stock_status', 'instock');
update_post_meta( $post_id, 'total_sales', '0' );
update_post_meta( $post_id, '_downloadable', 'yes' );
update_post_meta( $post_id, '_virtual', 'yes' );
update_post_meta( $post_id, '_sku', '54684845' );
update_post_meta( $post_id, '_regular_price', '75' );
` update_post_meta( $post_id, '_thumbnail_id', "../wp-content/uploads/2021/08/1149.jpg" );
update_post_meta( $post_id, '_downloadable_files', $downloadPicture );
}
解决方案
推荐阅读
- php - Vestacp - smpt 电子邮件、mail() 或 swiftmailer 无法使用 php
- google-app-engine - Google App Engine 配额错误,但没有超出配额
- apache-kafka - Kafka 分区日志真的不可变吗?为了使其真正不可变,日志可以与分布式账本集成吗?
- javascript - 有没有办法根据使用路由器做出反应的数组中的单击项目来呈现值?
- android - 检查 espresso 中的对话框(从异步任务创建)
- linux - Docker:go命令上的'go.mod:权限被拒绝'
- macos - 使用 clang++ 使用 SCons 编译 Antlr4 cpp 运行时。结果库给了我未定义的符号(macos)
- python - 2D点之间的最小距离Python 3代码
- python - Python中的while循环没有数字重复并限制在范围内
- scrapy - Scrapy crawlspider 不跟随链接