0
我製作了自定義模板來處理woocommerce(通過將文件夾複製到我的主題並對其進行重命名,我覆蓋了現有模板)。我加入這個頁面上的按鈕,應該使用下面的鏈接將產品添加到購物車:Woocommerce:對不起,無法購買此產品
<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.
的產品屬於「簡單產品」類型,並且它們是通過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();
}
我完全不知道可能會導致錯誤的原因。在環顧網絡之後,我變得毫無智慧。任何想法可能是什麼問題?
這個伎倆!奇怪的是,設置_regular_price和_sale_price是不夠的! :) 謝謝! –