javascript - 如果内容为空,则使用 php 隐藏选项卡
问题描述
链接到产品页面 第一个选项卡通过简码获取描述,第二个选项卡通过简码获取简短描述。我想要它,以便如果简短描述为空,则该选项卡将被删除。
我将此代码与 jquery 脚本一起使用,但似乎无法使其正常工作
// Remove tehnicki karakteristiki
function remove_tehnicki_karakteristiki() {
if ( !is_singular(['product']) ){ // only on product page
global $post, $product;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt ); // get short desc
if (empty($short_description) ) {
echo '<script>
jQuery(#elementor-tab-title-1562).hide();
</script>';
}
}
}
解决方案
更新:
function remove_tehnicki_karakteristiki() {
if ( !is_singular(['product']) ){ // only on product page
global $post, $product;
$short_description = apply_filters( 'woocommerce_short_description', $post->post_excerpt ); // get short desc
echo "
<script>
jQuery(function ($) {
$('.elementor-toggle .elementor-tab-content').filter(function () {
let element = ($(this).find('.elementor-section-wrap').length == 0 ? $(this) : $(this).find('.elementor-section-wrap'))
if (!new RegExp('([A-z0-9])', 'gm').test(element.html())) element.closest('.elementor-toggle-item').hide();
})
});
</script>";
}
}
推荐阅读
- xamarin - 如何以编程方式调整 xamarin 表单 Gridview 图像的大小?
- javascript - 单击 Tooltip 时更改 Bootstrap 的文本
- python - 绘制回归模型结果的 R 平方误差
- c# - 无法从远程 MQ 获取消息
- lagom - Lagom withPathParamSerializer
- tfs - VSTS Sprint 容量 - 无法选择活动
- docker - 在 Docker 中动态更改 Traefik 前端配置
- git - VSTS GIT REST API 忽略“ExcludeDeletes”;有解决方法吗?
- c# - 发送开发时发生意外错误,但未实时发生
- android - 没有帖子ID是否可以得到评论?