Adding a product description to the woocommerce ca

2019-06-12 22:49发布

How to add a short description to the woocommerce cart page (woocommerce/cart/cart.php) since the_content(); wasn't working at all.

2条回答
爷、活的狠高调
2楼-- · 2019-06-12 23:24

I was unable to use the above method but this worked for me

$postData = get_post($product_id);
$postExcerpt = $postData->post_excerpt;
echo apply_filters( 'woocommerce_short_description', $postExcerpt );
查看更多
乱世女痞
3楼-- · 2019-06-12 23:44

I figured that this could be solve by using:

echo apply_filters('the_content', get_post_field('post_content', $product_id));

This will display the full product description. If you want to display only an excerpt without shortcodes and all, you could use:

$excerpt = apply_filters('the_content', get_post_field('post_content', $product_id));
// remove shortcodes    
$excerpt = strip_shortcodes($excerpt);
// remove tags
$excerpt = strip_tags($excerpt);
// extract only 126 characters (this can be change to the amount you need).
$excerpt = substr($excerpt, 0, 126);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
echo $excerpt;
// add dots at the end
echo '...';
查看更多
登录 后发表回答