【问题标题】:Woocommerce archive product dont show the productsWoocommerce 存档产品不显示产品
【发布时间】:2017-03-16 17:17:07
【问题描述】:

我有一家商店,里面有 8k 种产品,我使用自己制作的插件导入了这些产品。

产品、类别和变体都是正确的。

所有店铺都是正确的。

但问题是每个分类的页面并没有输出产品,直到我给他们手动保存。

我已经禁用了主题和插件,并且原件继续存在同样的事情。

如果我通过覆盖存档产品手动更改查询,则可以看到所有产品,但分页和类别列表保持不变。

可能是一些元帖子吗?

有什么办法吗?

非常感谢大家。

我生成基本产品和变体产品的功能:

$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());
            }
        }

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    我找到了解决问题的方法:

    将这两个元标签添加到产品中:

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

    或

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

    在我的例子中,total_sale 为 0,因为它们是新产品。

    【讨论】:

      猜你喜欢
      • 2017-06-14
      • 1970-01-01
      • 2014-10-17
      • 2014-06-18
      • 2019-06-22
      • 2016-12-02
      • 2015-12-30
      • 1970-01-01
      • 2020-11-26
      相关资源
      最近更新 更多