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.

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

报告相同问题?