I want to add products with PHP code like below:
$post_information = array(
'post_title' => 'new item shop',
'post_content' => 'this is new item shop',
'post_type' => 'post',
'post_status' => 'publish'
);
$post_id = wp_insert_post($post_information);
but this code optimize for WooCommerce such as post type and guid and metadata and… Can someone help?
The method below is now out of date as WooCommerce have added the
wc_product_meta_lookup
table which also needs to be updated with some of the meta values.Woo have now provided a CRUD interface so use that instead.
Reviewer, please feel free to edit as you see fit.
Its pretty easy one you have worked out the data added in the post meta. Trouble I am having is adding downloadable products to the store.
below is the code i am using it lists all the post meta that is used by woo commerce. This publishes a product however the download link will not attach.
Originally when i started i made an error with the array that stores the download link producing a bad link “b” followed by a second download file that was correct. After fixing the array to match that of a product manually added it no loner will show a file. If anyone has info on this it would be greatly appreciated
hope this conforms to the quality standard 🙂