I'm trying to scrape a price with simple html DOM and set it as regular product price in Woocommerce.
Here is my actual code:
//Starting scrape
$html = file_get_html('http://sitenam.com/page-1/');
$price = $html->find('span[class="price"]', 0)->innertext;
//Starting post
$post = array(
'post_author' => 1,
'post_content' => 'Content Here',
'post_status' => "publish",
'post_title' => "Product Title Here",
'post_parent' => "product-title-here",
'post_type' => "product",
);
$post_id = wp_insert_post( $post, $wp_error );
wp_set_object_terms( $post_id, 'simple', 'product_type' );
add_post_meta( $post_id, '_regular_price', $price );
The product price is really saved as you can see in this image:
But the real problem is that the product price is not displayed on front end. Here's the screenshot:
Now on admin edit product page, if I click on "update" button, then the price is displayed on frontend product pages.
How can I automate this process from my code, without going in backend saving the product data?