从 WooCommerce 获取产品描述?

Get the Product description from WooCommerce?

我为 woocommerce 构建了一个自定义支付网关扩展,我将以 JSON 格式将所有数据(商品名称、成本、数量等)发布回支付提供商。

但是,我似乎无法通过项目描述。

有什么想法吗?

在获取 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;
}

WooCommerce:将产品简短描述添加到存档页面或在商店页面上显示产品简短描述

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