Can’t make the plugin work (Woodmart theme)

Plugin Author
malihu

(@malihu)

Hello,

The “Skaityti plačiau” link doesn’t work because it targets a tab which is handled (and initialized) by another script.

In order to make this work correctly, i.e. scroll smoothly and switch to the correct tab if necessary, you’ll to add some extra js code in your page template. Can you do this?

If yes, the javascript to add is:

(function($){
	$(window).on("load",function(){
		$("a.single_product_read_more.__mPS2id[href$='#tab-description']").on("click",function(e){
			e.preventDefault();
			$("#tab-title-description a[href$='#tab-description']").trigger("click");
			$.mPageScroll2id("scrollTo","#tab-description");
		});
	});
})(jQuery);

This will work for the “Skaityti plačiau” link you have in the product’s short description. If you need another link we’ll just need to change the selector.

If you want to add the script above via your theme/child-theme functions.php, the PHP code is:

function ps2id_custom_script(){
	wp_register_script( 'ps2id-custom-script', '', array('jquery', 'page-scroll-to-id-plugin-script'), '', true );
	wp_enqueue_script( 'ps2id-custom-script' );
	wp_add_inline_script( 'ps2id-custom-script', '(function($){
		$(window).on("load",function(){
			$("a.single_product_read_more.__mPS2id[href$='#tab-description']").on("click",function(e){
				e.preventDefault();
				$("#tab-title-description a[href$='#tab-description']").trigger("click");
				$.mPageScroll2id("scrollTo","#tab-description");
			});
		});
	})(jQuery);');
}
add_action( 'wp_enqueue_scripts', 'ps2id_custom_script' );

Let me know if it works

Hello,

Works both solutions, just needed a little bit modifications open bracket in custom js code:

(function($){
	$(window).on("load",function(){
		$("a.single_product_read_more.__mPS2id[href$='#tab-description']").on("click",function(e){
			e.preventDefault();
			$("#tab-title-description a[href$='#tab-description']").trigger("click");
			$.mPageScroll2id("scrollTo","#tab-description");
		});
	});
})(jQuery);

And in functions.php open bracket and single quotes of #tab-description:

function ps2id_custom_script(){
    wp_register_script( 'ps2id-custom-script', '', array('jquery', 'page-scroll-to-id-plugin-script'), '', true );
    wp_enqueue_script( 'ps2id-custom-script' );
    wp_add_inline_script( 'ps2id-custom-script', '(function($){
        $(window).on("load",function(){
            $("a.single_product_read_more.__mPS2id[href$=\'#tab-description\']").on("click",function(e){
                e.preventDefault();
                $("#tab-title-description a[href$=\'#tab-description\']").trigger("click");
                $.mPageScroll2id("scrollTo","#tab-description");
            });
        });
    })(jQuery);');
}
add_action( 'wp_enqueue_scripts', 'ps2id_custom_script' );

I want to leave correct code if anyone else needed it.

Thank you!

Plugin Author
malihu

(@malihu)

You’re welcome 🙂 Thanks for posting the code. I’m marking this as resolved but let me know if you need more help.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer