WooCommerce product images link to external URL?
-
I would be very grateful for a bit of assistance on making some adjustments to my WordPress site. My theme is Woocommerce’s Storefront. I don’t use a child theme. I also use the Code Snippets plugin to avoid editing directly in my files though I will edit the files if I have to.
There are two things I’d like to accomplish:
First, on my Archive/Catalog pages, I want the product image to lead to an external URL in a new tab and I want the product title to lead to the internal single product page. I’ve searched forums for help in accomplishing this and did find a piece of code that separates the image from the title, making the image lead to the external URL in the same tab and the title go to the single product page. I can’t figure out how to adjust this code to make the product image URL open to a new tab. Here is that code:
remove_action(‘woocommerce_before_shop_loop_item’, ‘woocommerce_template_loop_product_link_open’);
add_action(‘woocommerce_before_shop_loop_item_title’, ‘woocommerce_template_loop_product_link_open’, 15);add_action(‘woocommerce_before_shop_loop_item’, ‘woocommerce_add_aff_link_open’, 10);
add_action(‘woocommerce_before_shop_loop_item_title’, ‘woocommerce_add_aff_link_close’, 10);function woocommerce_add_aff_link_open(){
$product = wc_get_product(get_the_ID());
if( $product->is_type( ‘external’ ) )
echo ‘get_product_url() . ‘” class=”woocommerce-LoopProductImage-link”>’;
}function woocommerce_add_aff_link_close(){
$product = wc_get_product(get_the_ID());
if( $product->is_type( ‘external’ ) )
echo ‘‘;
}Second, I haven’t been able to find code that works on the single product page, but I also want this image to lead to an external URL in a new tab and do away with the image lightbox/zoom features.
Thank you so much for your consideration.
Christine
- The topic ‘WooCommerce product images link to external URL?’ is closed to new replies.