WooCommerce Product Image to External Link in New Window
-
I have an external link product and would like the featured image on the single product page to link to the external page in a new window.
Out of the box the image, when clicked, opens in a lightbox.
The section of code I have to adjust is in the product-image.php
<div class="images"> <?php if ( has_post_thumbnail() ) { $image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) ); $image_caption = get_post( get_post_thumbnail_id() )->post_excerpt; $image_link = wp_get_attachment_url( get_post_thumbnail_id() ); $image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ), array( 'title' => $image_title, 'alt' => $image_title ) );
Specifically I need to change this line:
$image_link = wp_get_attachment_url( get_post_thumbnail_id() );
I changed it to this:
$image_link = esc_url( $product->get_product_url() );
which accomplished the image opening the external link when clicked. However it’s opening in the same window and I’d like it to open in a new window.I tried this:
$image_link = esc_url( $product->get_product_url(), array('target' => '_blank', 'rel' => 'new_window') );
But now it just kind of refreshes the page and takes me nowhere.Suggestions? Thank you!
Page I’m trying this on.
- The topic ‘WooCommerce Product Image to External Link in New Window’ is closed to new replies.