How to open woocommerce product links in new tab ?

How to open woocommerce product links in new tab ?

Hey there is always a question asked on many wordpress forums that how can we open a woocommerce product link in a new tab so that user can select other products as well rather than going back and forth again and again.

This is not an easy task to do for someone who is a designer and for a beginner wordpress developer or a client.

So i decided to come up with a solution using woocommerce hooks which is a standard way of doing any custom tweaks to woocommerce functionalities. 

Lets get started.

You just need to open your functions.php file and paste the below snippet into it.

I have used woocommerce_template_loop_product_link_open hook to achieve this and added target=”_blank” in the anchor tag which opens a link in new tab.

/* Open Products in New Tab Woocommerce-DevelopingSense */

remove_action( 'woocommerce_before_shop_loop_item','woocommerce_template_loop_product_link_open', 10 );
add_action ( 'woocommerce_before_shop_loop_item', 'ami_function_open_new_tab', 10 );
function ami_function_open_new_tab() {
echo '<a target="_blank" href="' . get_the_permalink() . '" class="woocommerce-LoopProduct-link">';

This is a best way to do it rather than using jquery or javascript which bloats a website.

Thanks and if you need any assistance you can contact me here.

Do leave your valuable comments.