I want to post woocommerce product in wordpress but i wanted this product to be posted as External/Affiliate product. From this link i found a solution that [ wp_set_object_terms( $post_id, 8, ‘product_type’, false ); ] this code to be used to set it as External/Affiliate product But i need to know then where this code to be put then?

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' );

Read more here: Insert woocommerce product as External / Affiliate type


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: