I'm using wp_insert_post for adding a woocommerce product with taxonomy "product_cat". Here is my code.
First I add a new product.
$post_id = wp_insert_post( array(
'post_title' => 'My Title',
'post_content' => 'This is custom template',
'post_status' => 'publish',
'post_type' => "product",
) );
and here, I attached terms with that post
wp_set_post_terms( $post_id, array(12,13), 'product_cat' );
But on shop page when I click on that specific category on which I add my product, the product is not display on that category, but on backend (wp admin) I see the terms are attached with my product.