效果如下图:
代码:
add_action('wp_footer', function(){
if(is_product()):
?>
<script>
jQuery(function($){
const decCon = $('.woocommerce-product-details__short-description');
const conHeight = decCon.height();
if(conHeight < 120){
decCon.addClass('more');
decCon.after('<button class="showBtn" data-a="0">Read More</button>');
$('.showBtn').on('click', function(){
decCon.toggleClass('showAll');
if( $(this).data('a') == 0 ){
$(this).data('a', 1);
$(this).text('Read Less');
}else{
$(this).data('a', 0)
$(this).text('Read More');
}
});
}
});
</script>
另外需要CSS 配合:
.woocommerce-product-details__short-description{
max-height:105px;
overflow: hidden;
}