将产品描述添加到 woocommerce 购物车页面 [英] Adding a product description to the woocommerce cart page

查看:41
本文介绍了将产品描述添加到 woocommerce 购物车页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向 woocommerce 购物车页面 (woocommerce/cart/cart.php) 添加简短描述,因为 the_content(); 根本不起作用.

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

推荐答案

我认为这可以通过以下方式解决:

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 '...';

这篇关于将产品描述添加到 woocommerce 购物车页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆