I've tried so many different ways of handling this, but every way results in the same exact result. All I'm trying to do is programatically generate woo products.

As the most basic of implementations doesn't even seem to be working, I am at my wits end for resolving this.

I have tried this :

$new_product_post_id = wp_insert_post(
                'comment_status'    =>  'closed',
                'ping_status'       =>  'closed',
                'post_content' =>  'Test content',
                'post_author'       =>  1,
                'post_name'     =>  'test-post',
                'post_title'        =>  'test product title',
                'post_status'       =>  'publish',
                'post_type'     =>  'product',
                'tax_input' => array(
                    'product_cat' => array( 150 )

On the dashboard, in the products menu I can SEE the product and all of the data has been properly saved. Title, Content, Permalink, Category...everything saves correctly.

The issue is that the post NEVER displays on the front end, in the shop, in the sidebar, or anywhere.

If I click 'View' from within the post edit screen it takes me right to the single product listing.

only once I manually click 'Update' on the post does the post even appear inside of any of the queries.

Please....someone point me in the right direction before I rip my hair out. I've asked in both woo commerce support forums, but they're pretty unresponsive and I don't plan on ever getting a response.

closed as off-topic by Pieter Goosen, cybmeta, Mark Kaplun, kaiser Dec 4 '14 at 16:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    This really is Off-Topic. That being said, try this - set the product visibility: update_post_meta( $new_product_post_id, '_visibility', 'visible' ); - Maybe try using think link. – Howdy_McGee Dec 3 '14 at 19:32
  • little confused...how is this off topic at all? I'm directly referencing a core WordPress function...it just so happens to be i'm trying to create products and not posts. – EHerman Dec 3 '14 at 19:34
  • 1
    Well the WordPress function does work as you've stated the problem lies with WooCommerce and what it needs in a product to be added to the Catalog. After doing a little research it seems to me that WooCommerce takes a few Post Meta into consideration when deciding whether or not to show the product in the Catalog. To answer this question properly you would need to dive into the 3rd party plugin to see what it needs set so that it's added to the catalog. – Howdy_McGee Dec 3 '14 at 19:39
  • 1
    On that note, this is why whenever you "Update" the product WooCommerce updates these values to defaults ( instead of inserting it directly via code the post meta isn't set at all in the database and thus isn't considered in the catalog query ). – Howdy_McGee Dec 3 '14 at 19:41
  • Hey Howdy, I want to thank you for taking the time to help me out and post here. After updating the post meta update_post_meta( $new_product_post_id, '_visibility', 'visible' ); posts began to appear on the shop page. The categories still don't appear , but I'll work on that one. I'm glad that I could at least get the products appearing. If you want to add your first response as an answer, I'll mark it as correct. – EHerman Dec 3 '14 at 19:59

Glad you got it to work! Per my comment, WooCommerce takes Post Meta into consideration whenever deciding whether or not to add a Product to the Shop Catalog. It seems you were able to make it show up by updating the product visibility:

update_post_meta( $new_product_post_id, '_visibility', 'visible' );

I'm not 100% familiar with WooCommerce so should it take other post meta you can follow the references below:

Adding A Product To WooCommerce Programmatically

WooCommerce Update Product Visibility

There was a WordPress Stackexchange answer which listed a ton of Woo Meta but I can't seem to find it :/

  • 1
    Thanks again @Howdy_McGee! Just de-stressed my day ten fold. I'll also add, from my above comments, when you update the post meta _visibility option, the category appears in the sidebar as well. Really Really Really appreciate the help! – EHerman Dec 3 '14 at 20:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.