Notice: These forums are now retired and closed. For active support, please Submit a Ticket or visit our official WordPress.org community pages.
Kadence Theme | Kadence Blocks | Starter Templates | WooCommerce Email Designer | Ascend | Virtue | Pinnacle

link the product image to the External/Affiliate URL

Home / Forums / Virtue Theme / link the product image to the External/Affiliate URL

This topic is: Not a support question
[Not a support question]
Posted in: Virtue Theme
August 15, 2017 at 1:54 pm

WooCommerce Installed: On the single product page, I’d like to link the product image to the External/Affiliate URL instead of opening up the image in a lightbox.

Almost 1 year ago, exactly, you answered this question and it seem to work, at first. But now, on new sites, it doesn’t work.

Putting it at the end of FUNCTIONS.PHP (no child yet).

add_filter('woocommerce_single_product_image_html', 'custom_link_external_products', 20, 2);

function custom_link_external_products($output,$post_id) {
global $product;
if($product->product_type == 'external') {
$image_link = wp_get_attachment_url( get_post_thumbnail_id($post_id) );
$link = $product->get_product_url();
$output = str_replace($image_link, $link, $output);
}
return $output;
}

What is the latest correct way to link the product image to the affiliate URL? Does it matter if there is a 2nd image/gallery?

  • The forum ‘Virtue Theme’ is closed to new topics and replies.