woocommerce wp_set_post_terms only works for admin
<p>I'm using wp_insert_post for adding a woocommerce product with taxonomy "product_cat". Here is my code.</p>

<p>First I add a new product.</p>

<pre><code>$post_id = wp_insert_post( array(
            'post_title' =&gt; 'My Title',
            'post_content' =&gt; 'This is custom template',
            'post_status' =&gt; 'publish',
            'post_type' =&gt; "product",
        ) );
</code></pre>

<p>and here, I attached terms with that post</p>

<pre><code>wp_set_post_terms( $post_id, array(12,13), 'product_cat' );
</code></pre>

<p>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.</p>