That’s exactly what i mean, everything is working fine, it’s just that i have to click Publish/Update button before the image displays in the front end, can this work automatically without me clicking Publish/Update button?
this is my code
$string = “Air Filter”;
$slug = strtolower(trim(preg_replace(‘/[^A-Za-z0-9-]+/’, ‘-‘, $string)));
$product_array=array(
‘post_title’ => ‘Air Filter’,
‘post_content’ => ‘Air Filter’,
‘post_status’ => ‘publish’,
‘post_type’ => “product”,
‘comment_status’ => “opened”,
‘post_name’ => $slug,
);
// Create a simple WooCommerce product
$post_id = wp_insert_post( $product_array );
// Setting the product type
wp_set_object_terms( $post_id, ‘simple’, ‘product_type’ );
wp_set_object_terms( $post_id, 69, ‘product_cat’ );
$url = “https://WWW.SHOWMETHEPARTSDB2.COM/BIN/IMAGES/BOSCH/5437wsangle01.jpg”;
// Setting the product meta
update_post_meta( $post_id, ‘_sale_price’, 80 );
update_post_meta( $post_id, ‘_price’, 136 );
update_post_meta( $post_id, ‘_featured’, ‘yes’ );
update_post_meta( $post_id, ‘_stock’, ’23’ );
update_post_meta( $post_id, ‘_stock_status’, ‘instock’);
update_post_meta( $post_id, ‘fifu_image_url’, $url);
Thank you.
-
This reply was modified 5 years, 5 months ago by
advanztek.