只需创建一个新的函数来处理get_the_content的值(),以获得唯一的话的最大数量,并在末尾添加了“更多”链接:
function custom_single_product_summary(){
$maxWords = 50; // Change this to your preferences
$description = strip_tags(get_the_content()); // Remove HTML to get the plain text
$words = explode(' ', $description);
$trimmedWords = array_slice($words, 0, $maxWords);
$trimmedText = join(' ', $trimmedWords);
if(strlen($trimmedText) < strlen($description)){
$trimmedText .= ' — <a href="' . get_permalink() . '">Read More</a>';
}
echo $trimmedText;
}
然后在原来的使用重写代码,你试图使用:
remove_action('woocommerce_single_product_summary',
'woocommerce_template_single_excerpt', 20);
add_action('woocommerce_single_product_summary', 'custom_single_product_summary', 10);
修订答: 改变了行动钩来呼应VALU因为WooCommerce期望采取行动来打印输出。
长描述不支持阅读更多的产品。由于我们在标签上显示内容,因此没有用处。 – Yasir