Woocommerce, open terms and conditions in a new tab

Hey,

We have a Woocommerce and on the checkout page with a checkbox at the bottom to accept the terms and conditions. However, when we click on the link to read the terms and conditions, it doesn’t open the page as expected, it simply shows a box with the Cornerstone code of the Terms and conditions page in it. Is it possible to have the terms and conditions to open in a new tab instead ?

Hi @magikweb,

Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

Thank you.

Hi There,

Yes that is possible. It is working that way right now because of the following custom JS:

$( "a.woocommerce-terms-and-conditions-link" ).click(function( event ) {
	event.stopPropagation();
	window.location.href = "https://redrive.dk/handelsbetingelser/";
	return false;
});

Please remove that. Are you using shortcode to build that checkout page? We need to see your setup. Please provide credentials on a secure note. Removing that JS code will prevent opening of the page as popup but it will not yet open it on a new tab. We need to add target="_blank" on the link parameter but not sure at the moment how to implement.

I removed the code, it was an attempt I tried some times ago but it worked that way before the code was added. It didn’t change anything. I removed it though.

Hi There,

Thank you for the credentials.
Try this code instead:

jQuery(function($){
$( "a.woocommerce-terms-and-conditions-link" ).unbind( "click" );
$( "a.woocommerce-terms-and-conditions-link" ).click(function( event ) {
	
	 $(this).attr("target", "_blank");
    window.open( $(this).attr("href"));

    return false;
});

});

See this: https://screencast-o-matic.com/watch/cbXbcg2rD1
The first line of the code remove current function attached to the button that opens terms page on a popup. Then we add the function to open it in a new tab. Further customization from here would be getting into custom development which is outside the scope our support. Thank you for understanding.

Unfortunately that didn’t work either. I also tried to put your code in $(document).ready() but it didn’t do anything

Hey there,

Try replacing the previous code with the following code:

jQuery(function($){
$( "a.woocommerce-terms-and-conditions-link" ).unbind( "click" );
$( "body" ).on('click', 'a.woocommerce-terms-and-conditions-link', function( event ) {
	
	 $(this).attr("target", "_blank");
    window.open( $(this).attr("href"));

    return false;
});

});

Let us know how this goes!

1 Like

It worked! The terms and conditions opened in a new tab and in the box like before but it’s nothing a bit of Css can’t fix. Thanks alot!

You’re welcome. Please note that since this involves custom code, fixing issues arising from the use of it or further enhancements would be outside the scope of our support.

Thanks.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.