Automatically inserted post needs update?
-
I have a function which automatically inserts a woocommerce product once a custom type post called daily_cartoon has been added.
This is the code of the function:
function convert_daily_cartoon_into_product($post_id){ if( ( $_POST['post_status'] == 'publish' ) && ( $_POST['original_post_status'] != 'publish' ) ) { // Create post object $post = array( 'post_title' => $_POST['post_title'], 'post_type' => 'product', 'post_status' => 'publish', 'tax_input' => array( 'product_cat' => 14 ) ); // Insert the post into the database $new_print = wp_insert_post( $post ); update_post_meta( $new_print, '_thumbnail_id', get_post_thumbnail_id( $post_id ) ); update_post_meta( $new_print, '_regular_price', 5 ); update_post_meta( $new_print, '_price', 5 ); } } add_action('publish_daily_cartoon', 'convert_daily_cartoon_into_product');
Everything looks fine: the product is added, complete with all the data, i.e. price, category, status published, etc.
But for some reason, it doesn’t show up on the website product page until I go edit the new product and click ‘update’ – even though I change nothing.
Anyone?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Automatically inserted post needs update?’ is closed to new replies.