【问题标题】:Hide tab if content is empty using php [closed]如果内容为空,则使用 php 隐藏选项卡 [关闭]
【发布时间】:2021-11-20 19:04:53
【问题描述】:

Link to staging site

Link to product page 第一个选项卡通过简码获取描述, 第二个通过简码获取简短描述。 我想要它,以便如果简短描述为空,则该选项卡会被删除。

标签是这个

我将此代码与 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>';
    } 
}
}

【问题讨论】:

  • 你能像下面这样对 Javascript 选择器使用双引号进行测试吗? jQuery("#elementor-tab-title-1562").hide();
  • @RupakNepali 我测试过,它不起作用

标签: javascript php jquery wordpress woocommerce


【解决方案1】:

更新:

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>";

    }
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-08
  • 2021-07-12
  • 1970-01-01
  • 2020-02-18
  • 2019-04-11
  • 2016-03-06
  • 1970-01-01
相关资源
最近更新 更多