Woocommerce 在单击按钮时打开单个产品选项卡

Woocommerce open single product tab on button click

在我的单个产品页面上,我有一个按钮,我想在该按钮上单击带有 id="cely-popis" 的特定按钮来打开名为“描述”的默认产品选项卡。只有当另一个选项卡比“描述”处于活动状态时才执行此操作。

$("#cely-popis").click(function() {
    $('html, body').animate({
        scrollTop: $("#tab-description").offset().top - 64
    }, 2000);

    $('.nav-link[href=tab-description]').trigger('click');
});

您可以使用此行定位描述标签 link。

$('a[href="#tab-description"]').trigger('click')

我找到了解决方案:

$('#cely-popis').click(function(e) {
    e.preventDefault();
    
    // smooth scroll to section
    $('html, body').animate({
        scrollTop: $('#tabs-container').offset().top - 32
    }, 2000);

    // add "active" class
    $('.wc-tabs li a').each(function() {
        if ($(this).hasClass('active')) {
            $(this).removeClass('active');
        }
    }); 

    $('.wc-tabs li#tab-title-description a').addClass('active');
    $('#tab-description').addClass('active');
    $('.woocommerce-Tabs-panel').css('display', 'none');
    $('#tab-description').css('display','block');
});