.php方法中如何隐藏按钮,php - 在Woocommerce的长产品说明中添加“更多” /“更少”按钮:当不需要按钮时,如何隐藏该按钮? - 堆栈内存溢出...

我正在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...');

});

});

因此,目前,“阅读更多/阅读较少”切换功能非常完美,但是我真的很想知道如何在不需要的地方将其隐藏在简短的说明中! 谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值