2017-08-01 166 views
1

我爲woocommerce構建了自定義支付網關擴展,並將所有數據(項目名稱,成本,數量等)以JSON格式發回給支付提供商。從WooCommerce獲取產品描述?

但是,我似乎無法獲得物品描述。

任何想法?

回答

1

您可以在車對象的項目,得到了WP_post對象的實例時,這樣說:

foreach(WC()->cart->get_cart() as $cart_item){ 
    // Get an instance of Product WP_Post object 
    $post_obj = get_post($cart_item['product_id']); 

    // HERE the product description 
    $product_desciption = $post_obj->post_content; 

    // The product short description 
    $product_short_desciption = $post_obj->post_excerpt; 
} 
+0

謝謝@LoicTheAztec這很好! – carlhandy

+0

哦,對不起。我相當新的stackoverflow。 – carlhandy

+0

@carlhandy不要......不客氣 – LoicTheAztec

0

WooCommerce:添加產品簡短說明存檔頁面或顯示產品簡述上店頁

function vitahc_excerpt_in_product_archives() { 
the_excerpt(); 
} 
add_action('woocommerce_after_shop_loop_item_title','vitahc_excerpt_in_product_archives', 10);