1

I'm trying to link products on my Woocommerce shop page directly to the external/affiliate site by clicking on the product's image.

I created a child theme of my current theme and am working in a child's version of the Woocommerce "content-product.php" file.

Found a few similar topics, but my content-product.php file looks differently, so that's where I got lost.

Can anyone see where I should add/change what exactly to have the product images redirect directly to the external site?

For some reason I couldn't paste the code in here nicely but the full one can be viewed at http://lifestylespot.nl/code.txt

I figured (according to info found elsewhere) that the following would do the trick:

Replacing:

global $product;

by

global $product;
if(!is_single()) $product_url = get_post_meta( $product->id, '_product_url', true );
if(empty($product_url)) $product_url = get_permalink();
![enter image description here][1]?>

That did the trick. But it made my shop page look like: https://i.stack.imgur.com/uu3a7.png

Thanks in advance!

simonvk
  • 76
  • 1
  • 2
  • 10

1 Answers1

3

I got it working.

Simply changed:

    <a href="<?php the_permalink(); ?>">

to:

    <a href="<?php echo esc_url( $product->get_product_url() ) ?>">

And to open the affiliate link in a new window:

<a href="<?php echo esc_url( $product->get_product_url() ) ?>" target="_blank">
Avi
  • 21,182
  • 26
  • 82
  • 121
simonvk
  • 76
  • 1
  • 2
  • 10