dongxun1244 2017-03-11 18:04
浏览 71
已采纳

Woocommerce存档产品不显示产品

I have a store with 8k products that I imported with a plugin made by me.

The products, the categories and the variations are all correct.

All shop is correct.

But the problem is the page of each category does not output the products until I give them to manually save one by one.

I have disabled the theme and the plugin and the same thing continues with the originals.

If I change the query manually by overriding the archive-product, all the products are seen, but the pagination and category listing remain the same.

Could it be for some meta-post?

Any solution?

Thank you very much to all.

My function to generate a basic and variant product:

$post = array(
            'post_author' => 1,
            'post_content' => $this->getDescription(),
            'post_status' => 'publish',
            'post_title' => $this->getName(),
            'post_parent' => '',
            'post_type' => 'product'
        );

        $postId = wp_insert_post($post);
        $this->setId($postId);

        if ($this->getId()) {
            update_post_meta($this->getId(), '_sku', $this->getSku());
            update_post_meta($this->getId(), '_visibility', 'visible');

            wp_set_object_terms($postId, $this->getCategories(), 'product_cat');

            $this->getImageXML();

            update_post_meta($this->getId(), '_price', $this->price);
            update_post_meta($this->getId(), '_regular_price', $this->price);

            wp_set_object_terms($this->getId(), $this->getType(), 'product_type', false);

            if ($this->getType() == 'simple') {
                update_post_meta($this->getId(), '_manage_stock', 'yes');
                update_post_meta($this->getId(), '_stock', $this->getStock());
            } else {
                $talla = wc_attribute_taxonomy_name('Größe');
                $attributes = array(
                    $talla => array(
                        'name' => $talla,
                        'value' => '',
                        'is_visible' => '1',
                        'is_variation' => '1',
                        'is_taxonomy' => '1'
                    )
                );
                wp_set_object_terms($this->getId(), $this->getAtributos(), $talla);
                update_post_meta($this->getId(), '_product_attributes', $attributes);

                foreach ($this->getVariants() as $key => $variant) {
                    $variation = array(
                        'post_title' => 'Product #' . $this->getId() . ' Variation',
                        'post_content' => '',
                        'post_status' => 'publish',
                        'post_parent' => $this->getId(),
                        'post_type' => 'product_variation'
                    );
                    $variationId = wp_insert_post($variation);
                    update_post_meta($variationId, '_sku', $variant['ean']);
                    update_post_meta($variationId, '_regular_price', $this->price);
                    update_post_meta($variationId, '_price', $this->price);
                    update_post_meta($variationId, '_manage_stock', 'yes');
                    update_post_meta($variationId, '_stock', $variant['stock']);
                    if ($variant['stock'] > 0) {
                        update_post_meta($variationId, '_stock_status', 'instock');
                    } else {
                        update_post_meta($variationId, '_stock_status', 'outofstock');
                    }
                    update_post_meta($variationId, 'attribute_' . $talla, strtolower(str_replace('/', '', $variant['talla'])));
                }
                WC_Product_Variable::sync($this->getId());
                WC_Product_Variable::sync_attributes($this->getId());
            }
        }
  • 写回答

1条回答 默认 最新

  • dtsc14683 2017-03-16 09:17
    关注

    I found the solution to my problem:

    Add this two meta_tags to product:

    update_post_meta($yourID, 'total_sales', 0);
    update_post_meta($yourID, '_stock_status', 'instock');
    

    or

    update_post_meta($yourID, 'total_sales', 0);
    update_post_meta($yourID, '_stock_status', 'outofstock');
    

    In my case total_sale is 0 because they are new products.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历