我想在wordpress中发布woocommerce产品,但我希望将此产品发布为External / Affiliate产品。从this link我找到了一个解决方案[wp_set_object_terms($ post_id,8,'product_type',false); ]此代码用于将其设置为External / Affiliate产品但是我需要知道那么这个代码放在哪里呢?
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.google.com');
update_post_meta($post_id, '_button_text' , 'Buyit' );
update_post_meta($post_id, '_aioseop_description' , 'Short description of My Product' );
update_post_meta($post_id, '_visibility' , 'visible' );
答案 0 :(得分:0)
她是解决方案:
wp_set_object_terms( $post_id, 'external', 'product_type');