在WooCommerce中,如何限制商店页面中的简短产品描述?我添加了以下代码:
add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_single_excerpt', 5);
但不能将其限制为40个字符。
谢谢!!!
而不是直接在插件中编辑文件(这是一个非常糟糕的主意,因为一旦更新了插件,您所做的所有更改都将丢失!)
add_filter('woocommerce_short_description', 'limit_woocommerce_short_description', 10, 1);
function limit_woocommerce_short_description($post_excerpt){
if (!is_product()) {
$post_excerpt = substr($post_excerpt, 0, 20);
}
return $post_excerpt;
}
然后将其粘贴到主题的functions.php文件中。
并在您要显示产品说明的位置使用此行-
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ); ?>
使用此代码更改“商店页面而非产品详细页面”上的“限制”。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句