0
votes

I need to create a product manually from php script (e.g. i'm developing a custom front-end form to insert products)

Googling i see some support forum create manually a post (using wp_insert_post function). I think this solution is not reliable (with a woocommerce update things may changes).

I need a wc function that does it for me, a sort of wc_create_product (like wc_create_order function).

I've found WC_API_Products::create_product() seems to be what i need but on the web i could not find any additional documentation or usage example except the code comment. Additionally this function is not listed on woocommerce official api doc at https://docs.woothemes.com/wc-apidocs/.

I need to know if this function is thought for internal use or maybe for external developer like me.

Does anyone have some information about it?

thanks

1
It is in the REST API docshelgatheviking
Thanks, you are right! So i guess the function it is only usable within REST protocol... So my question persist: is there a function to create product in a font-end form?? i don't know why all post type have their crete function except wc-product..luk_z
No other post types have specific creation functions. Any/all post types can be created via wp_insert_post()helgatheviking

1 Answers

3
votes

In Woocommerce, products are represented by objects of the class WC_Product which is documented here.

The documentation dicourages us from using the constructor explicitly, however, this works. We can create products by calling the constructor and then add properties.

$product = new WC_Product();
$product->set_name('My Product')
...