Hi there.
I have added a custom tabs to my single product page:
- Product Details (originally Product Description)
- Indications of Use (custom)
- Reviews
And I have created a menu in the sidebar to link to these tabs as if they had anchors:
- #description
- #indications
- #reviews
I tried to implement JS from this post:
Here is the code I modified:
(function($){
var tabnav = location.href.split("#").slice(-1)[0];
if ( tabnav == 'description' ) {
$( document ).ready ( function() {
var navbar = $('.x-navbar').outerHeight();
$('.x-tab-pane, .x-nav-tabs-item').removeClass('active');
$('.description_tab, .description_pane').addClass('active');
setTimeout ( function() {
$('html, body').animate({
scrollTop: $(".woocommerce-tabs").offset().top - navbar
}, 1000);
}, 750 );
} );
}
})(jQuery);
(function($){
var tabnav = location.href.split("#").slice(-1)[0];
if ( tabnav == 'reviews' ) {
$( document ).ready ( function() {
var navbar = $('.x-navbar').outerHeight();
$('.x-tab-pane, .x-nav-tabs-item').removeClass('active');
$('.reviews_tab, .reviews_pane').addClass('active');
setTimeout ( function() {
$('html, body').animate({
scrollTop: $(".woocommerce-tabs").offset().top - navbar
}, 1000);
}, 750 );
} );
}
})(jQuery);
(function($){
var tabnav = location.href.split("#").slice(-1)[0];
if ( tabnav == 'indications' ) {
$( document ).ready ( function() {
var navbar = $('.x-navbar').outerHeight();
$('.x-tab-pane, .x-nav-tabs-item').removeClass('active');
$('.indications-of-use_tab, .indications-of-use_tab_pane').addClass('active');
setTimeout ( function() {
$('html, body').animate({
scrollTop: $(".woocommerce-tabs").offset().top - navbar
}, 1000);
}, 750 );
} );
}
})(jQuery);
And it works if I manually add the anchor at the end of the URL - click here to see it working:
But it doesn’t work when click the menu items. What am I missing?