【发布时间】:2014-06-08 10:51:11
【问题描述】:
我正在尝试以编程方式(使用 PHP)将 Woocommerce 产品插入我的网站。我所有的产品都是外部/附属产品类型。我已经使用下面的代码成功创建了一个产品,但它默认为“简单产品”产品类型。我的问题是如何使用我的 PHP 帖子创建或元数据更新将产品类型更改为 External/Affiliate?
我试过这个命令没有成功:
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' );
【问题讨论】:
标签: php wordpress woocommerce