Woocommerce:抱歉,无法购买此产品

Woocommerce: Sorry, this product cannot be purchased

我制作了一个自定义模板来使用 woocommerce(我通过将文件夹复制到我的主题并重命名来覆盖现有模板)。我在此页面上添加了一个按钮,该按钮应使用以下 link:

将产品添加到购物车
<a class="add-to-cart" href="?add-to-cart=<?php echo get_the_ID(); ?>"><?php _e('Add to cart'); ?></a>

但是,当我转到我的购物车时,我收到以下消息:

Sorry, this product cannot be purchased.

产品类型为 'simple product',它们是从 excel 文件以编程方式添加的。它们是通过以下方式创建的:

public function handleAutomateRequest() 
{
    $time = time();

    for($_SESSION['records_processed']; $_SESSION['records_processed'] < $_SESSION['record_count']; $_SESSION['records_processed']++)
    {
        $row = $this->create_row_object($_SESSION['records'][$_SESSION['records_processed']]);
        $post = $this->get_post($row);

        $product = array();
        $product['ID'] = !is_null($post) ? $post->id : '';
        $product['post_name'] = $row->slug;
        $product['post_title'] = $row->title;
        $product['post_content'] = '';
        $product['post_type'] = 'product';
        $product['post_status'] = 'publish';
        $product['post_date'] = $row->date;
        $product['post_date_gmt'] = $row->date_gmt;

        if($row->title != '') {
            $post_id = wp_insert_post($product);
            wp_set_object_terms($post_id, array($row->brand), 'product_cat');

            $this->add_product_meta($post_id, $row);

            update_post_meta($post_id, '_sku', '#' . $post_id);
            update_post_meta($post_id, '_sale_price', $row->price);
            update_post_meta($post_id, '_regular_price', $row->price);
        }

        if(time() > $time + 10) 
            break;
    }

    echo $_SESSION['records_processed'] != $_SESSION['record_count'] ? $_SESSION['records_processed'] . ' / ' . $_SESSION['record_count'] : 'DONE';
    die();
}

我完全不知道是什么导致了这个错误。在网上看了一圈后,我变得none更聪明了。知道问题出在哪里吗?

查看文件...如果产品不可购买,则会生成错误消息。

函数中的一个测试似乎是

 elseif ( $this->get_price() === '' ) {
        $purchasable = false;

哪个可以找post_meta_price。所以尝试为每条记录设置_price