woocommerce offtopic - Simple Product not displaying in frontend

i written a script in woocmmerce to import 1000 simple productmy script is working fine and it's added all the pr

i written a script in woocmmerce to import 1000 simple product my script is working fine and it's added all the product at my wordpress site however the products are not showing in front end store. when i open the single product it show the product with prices but when i search the category it's not showing

when i edit the product and update it from admin panel by clicking update button without changing anything then the product display at my store i am not able to figure out the issue please help NOTE 1. i have already tried deleting Transients and hence it's not working

here is my Code

$querystr = "SELECT * FROM `table_name`";$pageposts = $wpdb->get_results($querystr, OBJECT);
foreach($pageposts as $productpost) {
            $post = array(
                     'post_title'   => $productpost->attribute,
                     'post_excerpt' => '<pre> '.$productpost->porduct_name."<br/>".$productpost->description.' <pre>',
                     'post_status'  => "publish",
                     'post_content' => 'test',
                     'post_name'    => $productpost->attribute, //name/slug
                     'post_type'    => "product"
                     );
                    $new_post_id = wp_insert_post( $post);
                    wp_set_object_terms ($new_post_id,'simple','product_type');
                    wp_set_object_terms( $new_post_id, 2321, 'product_cat');
                    update_post_meta( $new_post_id, '_stock_status', 'instock');
                    update_post_meta( $new_post_id, '_weight', "0.06" );
                    update_post_meta( $new_post_id, '_sku', $productpost->sku);
                    update_post_meta( $new_post_id, '_stock', "100" );
                    update_post_meta($new_post_id, '_regular_price', (float)$productprice);
                    update_post_meta($new_post_id, '_price', (float)$productprice);
                    update_post_meta($new_post_id,'_meta_key','_visiblity');
                    require_once(ABSPATH . 'wp-admin/includes/media.php');
                    require_once(ABSPATH . 'wp-admin/includes/file.php');
                    require_once(ABSPATH . 'wp-admin/includes/image.php');
                    $thumb_url = "image_path.jpg";

                    if (@getimagesize($thumb_url)) {
                    $tmp = download_url( $thumb_url );
                    preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
                    $file_array['name'] = basename($matches[0]);
                    $file_array['tmp_name'] = $tmp;
                    if ( is_wp_error( $tmp ) ) {
                    @unlink($file_array['tmp_name']);
                    $file_array['tmp_name'] = '';
                    $logtxt .= "Error: download_url error - $tmp\n";
                    }else{
                    $logtxt .= "download_url: $tmp\n";
                    }
                    //use media_handle_sideload to upload img:
                    $thumbid = media_handle_sideload( $file_array, $new_post_id, 'gallery desc' );
                    // If error storing permanently, unlink
                    if ( is_wp_error($thumbid) ) {
                    @unlink($file_array['tmp_name']);
                    //return $thumbid;
                    $logtxt .= "Error: media_handle_sideload error - $thumbid\n";
                    }else{
                    $logtxt .= "ThumbID: $thumbid\n";
                    set_post_thumbnail($new_post_id, $thumbid);
                    }
                    }
                update_post_meta( $new_post_id, '_visibility', 'visible' );
                update_post_meta($new_post_id, 'post_status', 'publish');

i written a script in woocmmerce to import 1000 simple product my script is working fine and it's added all the product at my wordpress site however the products are not showing in front end store. when i open the single product it show the product with prices but when i search the category it's not showing

when i edit the product and update it from admin panel by clicking update button without changing anything then the product display at my store i am not able to figure out the issue please help NOTE 1. i have already tried deleting Transients and hence it's not working

here is my Code

$querystr = "SELECT * FROM `table_name`";$pageposts = $wpdb->get_results($querystr, OBJECT);
foreach($pageposts as $productpost) {
            $post = array(
                     'post_title'   => $productpost->attribute,
                     'post_excerpt' => '<pre> '.$productpost->porduct_name."<br/>".$productpost->description.' <pre>',
                     'post_status'  => "publish",
                     'post_content' => 'test',
                     'post_name'    => $productpost->attribute, //name/slug
                     'post_type'    => "product"
                     );
                    $new_post_id = wp_insert_post( $post);
                    wp_set_object_terms ($new_post_id,'simple','product_type');
                    wp_set_object_terms( $new_post_id, 2321, 'product_cat');
                    update_post_meta( $new_post_id, '_stock_status', 'instock');
                    update_post_meta( $new_post_id, '_weight', "0.06" );
                    update_post_meta( $new_post_id, '_sku', $productpost->sku);
                    update_post_meta( $new_post_id, '_stock', "100" );
                    update_post_meta($new_post_id, '_regular_price', (float)$productprice);
                    update_post_meta($new_post_id, '_price', (float)$productprice);
                    update_post_meta($new_post_id,'_meta_key','_visiblity');
                    require_once(ABSPATH . 'wp-admin/includes/media.php');
                    require_once(ABSPATH . 'wp-admin/includes/file.php');
                    require_once(ABSPATH . 'wp-admin/includes/image.php');
                    $thumb_url = "image_path.jpg";

                    if (@getimagesize($thumb_url)) {
                    $tmp = download_url( $thumb_url );
                    preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $thumb_url, $matches);
                    $file_array['name'] = basename($matches[0]);
                    $file_array['tmp_name'] = $tmp;
                    if ( is_wp_error( $tmp ) ) {
                    @unlink($file_array['tmp_name']);
                    $file_array['tmp_name'] = '';
                    $logtxt .= "Error: download_url error - $tmp\n";
                    }else{
                    $logtxt .= "download_url: $tmp\n";
                    }
                    //use media_handle_sideload to upload img:
                    $thumbid = media_handle_sideload( $file_array, $new_post_id, 'gallery desc' );
                    // If error storing permanently, unlink
                    if ( is_wp_error($thumbid) ) {
                    @unlink($file_array['tmp_name']);
                    //return $thumbid;
                    $logtxt .= "Error: media_handle_sideload error - $thumbid\n";
                    }else{
                    $logtxt .= "ThumbID: $thumbid\n";
                    set_post_thumbnail($new_post_id, $thumbid);
                    }
                    }
                update_post_meta( $new_post_id, '_visibility', 'visible' );
                update_post_meta($new_post_id, 'post_status', 'publish');
Share Improve this question edited Jul 14, 2017 at 21:06 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jul 14, 2017 at 19:13 Neha KapoorNeha Kapoor 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Set product_visibility to visible, _stock_status key to instock, _stock key to some value also post_date and post_date_gmt set to date lower than today's date.

After placing this in your script your simple product become visible on shop page.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744784908a4593563.html

相关推荐

  • woocommerce offtopic - Simple Product not displaying in frontend

    i written a script in woocmmerce to import 1000 simple productmy script is working fine and it's added all the pr

    2天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信