
How to open woocommerce product links in new tab ?
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.
WHERE I AM HOSTING MY WEBSITE ? IT IS ON SITEGROUND…CHECK MY REVIEW HERE
Do leave your valuable comments.