2016-01-23 136 views
0

我有一個插件,它以編程方式成功地將自定義產品添加到Woocommerce。問題是,當用戶第一次導航到產品頁面時,沒有「添加到購物車」按鈕可見。我可以通過編輯產品並手動解決此問題,而無需觸摸其他任何東西。我不知道爲什麼這會起作用,我想以編程方式解決它。Woocommerce'添加到購物車'按鈕在程序添加產品後丟失

要想從: enter image description here

  1. 我點擊 「編輯」
  2. 我點擊 「更新」
  3. 然後我看到:

enter image description here

我如何以編程方式顯示「添加到購物車」按鈕?

開火「初始化」:

public function createRaffleProduct(){ 
    global $CRG_productName; 
    global $CRG_regularPrice; 
    $post = array(
     'post_author' => $user_id, 
     'post_content' => '', 
     'post_status' => "publish", 
     'post_title' => $CRG_productName, 
     'post_parent' => '', 
     'post_type' => "product", 
    ); 
    //Create post: 
    $post_id = wp_insert_post($post, $wp_error); 
    update_post_meta($post_id, '_visibility', 'visible'); 
    update_post_meta($post_id, '_stock_status', 'instock'); 
    update_post_meta($post_id, 'total_sales', '0'); 
    update_post_meta($post_id, '_downloadable', 'no'); 
    update_post_meta($post_id, '_virtual', 'yes'); 
    update_post_meta($post_id, '_regular_price', $CRG_regularPrice); 
    update_post_meta($post_id, '_sale_price', "1"); 
} 
+1

乍一看,我想你可能會缺少'_price'元鍵。仔細查看'save_post'上發生了什麼,並確保您使用的是全部相同的元。 – helgatheviking

+0

感謝您提及它,但這不是關於Codeception的問題,所以我刪除了標籤並解釋了爲什麼您提到了它。 – Naktibalda

+0

Helgathevicking,工作! –

回答

2

編程時創造一個產品,你必須確保所有正在使用的相同的元作爲WooCommerce產生的save_post

從您的代碼中,您錯過了_price元鍵。如果沒有_price,那麼產品不是purchasable,並且不會顯示添加到購物車按鈕。

相關問題