Woocommerce 添加具有外部/附属类型的产品 [英] Woocommerce Add Product with External/Affiliate Type
问题描述
我正在尝试以编程方式(使用 PHP)将 Woocommerce 产品插入我的网站.我所有的产品都是外部/附属产品类型.我已经使用下面的代码成功创建了一个产品,但它默认为简单产品"产品类型.我的问题是如何使用我的 PHP 帖子创建或元数据更新将产品类型更改为外部/附属机构?
I am trying to programmatically (using PHP) insert a Woocommerce product into my site. All of my products are External/Affiliate product type. I have successfully created a product with the code below, but it is defaulting to a "Simple Product" product type. My question is how do I change the product type to External/Affiliate using my PHP post creation or metadata updates?
我尝试了这个命令但没有成功:
I've attempted this command with no success:
update_post_meta($post_id, 'product-type' , 'external' );
以下是用于创建分配了基本属性的产品的代码:
Here is the code used to create the product with bare-bones attributes assigned:
require_once("../wp-load.php");
$new_post = array(
'post_title' => "Title of My Product",
'post_content' => 'Full description of My Product',
'post_status' => 'publish',
'post_type' => 'product',
'is_visible' => '1'
);
$post_id = wp_insert_post($new_post);
update_post_meta($post_id, '_sku', '5000' );
update_post_meta($post_id, '_regular_price' , '99.95');
update_post_meta($post_id, '_product_url' , 'http://www.myaffiliatesURL.com');
update_post_meta($post_id, '_button_text' , 'Buy from My Affiliate' );
update_post_meta($post_id, '_aioseop_description' , 'Short description of My Product' );
update_post_meta($post_id, '_visibility' , 'visible' );
推荐答案
可以试试这个.
wp_set_object_terms ($post_id, 'external', 'product_type');
您还需要设置parent_id"
You also need to set the 'parent_id'
这篇关于Woocommerce 添加具有外部/附属类型的产品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!