2017-08-01 164 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);