kukko
kukko

Reputation: 653

Programmatically created products doesn't show on WooCommerce

I created a cron job to fetch wholesaler product list and insert them into the database.

But when I create a product in this way, it's doesn't show in the shop, only in the admin. After I enter into the edit page of any product and click the save button without make changes on the product, this product apear in the shop.

What would be the problem with the products?

Upvotes: 2

Views: 592

Answers (2)

khasru
khasru

Reputation: 169

I faced this issue, In my case it was language issue, we installed polylang, when we import product using API we missed to set the default language.

For poly-lang i added below code.

global $polylang;


$language_code='de';
     
if (function_exists('pll_set_post_language')) {                
      pll_set_post_language($post_id, $language_code);
   } else {
      error_log(print_r($post_id . ' poly-lang not found!'));
   } 

Upvotes: 1

LoicTheAztec
LoicTheAztec

Reputation: 253919

When inserting a product to the database, If you want it to appear on front end, you need in wp_posts table to set 'post_status' key with a value of 'publish'.
Without it, it doesn't appear on front end.

Also the 'post_date' and 'post_date_gmt' need to have a date lower than "today"

Check also in wp_postmeta table that you are also setting:

  • '_visibility' key to 'visible' value
  • '_stock_status' key to 'instock' value
  • '_stock' with some value…

Once done, your products should appear on shop page, without editing them.

Upvotes: 4

Related Questions