Php 将woocommerce产品作为外部/附属类型插入
我想在wordpress中发布woocommerce产品,但我想将此产品作为外部/附属产品发布。从中我找到了一个解决方案,[wp_set_object_terms($post_id,8,'product_type',false);]该代码用于将其设置为外部/附属产品,但我需要知道该代码将放在何处Php 将woocommerce产品作为外部/附属类型插入,php,wordpress,Php,Wordpress,我想在wordpress中发布woocommerce产品,但我想将此产品作为外部/附属产品发布。从中我找到了一个解决方案,[wp_set_object_terms($post_id,8,'product_type',false);]该代码用于将其设置为外部/附属产品,但我需要知道该代码将放在何处 require_once("../wp-load.php"); $new_post = array( 'post_title' => "Title of My Product",
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' );
她的解决方案是:
wp_set_object_terms( $post_id, 'external', 'product_type');
好啊你能解释一下如何使用默认选项作为外部/附属产品发布吗?我不想手动操作。我想发布代码中的产品数据我的目标是通过脚本而不是手动过程发布产品。这个脚本应该发布新的产品作为外部得到了吗?