我想以編程方式(使用PHP)插入一個Woocommerce產品到我的網站。我所有的產品都是外部/聯盟產品類型。我已經成功創建了一個包含以下代碼的產品,但它缺省爲「簡單產品」產品類型。我的問題是如何使用我的PHP後期創建或元數據更新將產品類型更改爲External/Affiliate?Woocommerce添加產品與外部/聯盟類型
我已經嘗試沒有成功這個命令:
update_post_meta($post_id, 'product-type' , 'external');
下面是用於創建具有裸機屬性的產品分配代碼:
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,8的文件名,「產品類型',false); )... ??? –