我正在Woomcommerce商店工作,该商店的产品说明长度各不相同。 我添加了一个“阅读更多” /“阅读较少”的按钮,该按钮可用于较长的产品说明。 但是,在简短的说明中,该按钮是可见的,但显然没有任何作用,因为没有任何可切换的内容。 如何隐藏简短说明中的按钮?
这是新模板的PHP / single-product / short-description.php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
global $post;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt );
if ( ! $short_description ){
return;
}
?>
这是javascript:
$(document).ready(function () {
$('.readmore').click(function (event) {
event.preventDefault();
var description = document.querySelector('.product-description');
console.log(description.style.height)
if (description.style.height === ''){
description.style.height = 'auto';
} else if (description.style.height === 'auto'){
description.style.height = '';
}
else{
description.style.height = '92px';
}
$(this).text($(this).text() == 'Read less...' ? 'Read more...' : 'Read less...');
});
});
因此,目前,“阅读更多/阅读较少”切换功能非常完美,但是我真的很想知道如何在不需要的地方将其隐藏在简短的说明中! 谢谢!