Currently I'm using the Woocommerce plugin for affiliate products. I would like to be able to click on the thumbnail on the main page and go directly to amazon, for example. Currently it's setup so that once clicked it goes to the product detail page on my site. From there you can get to the amazon page. However, fewer clicks the better.
So I found the hook in the content-product.php page. What I did was wrap the whole thing in a URL and used a custom field to add in the URL. Doesn't work as intended. What happens is that the URL goes to amazon only when using one of the sale flash options. When turned off, the URL does not go to amazon, but to the product page on my site. I don't know where else to place the URL wrapper.
So i tried looking for the <a href="<?php the_permalink(); ?>">
that is currently controlling where the thumbnail goes. I traced the function to the woocommerce-template.php file. That's where I hit a dead end. I'm not sure where it is for the thumbnail currently.
Here is my modified code that works partially in the content-product.php page:
<div class="thumbnail-wrapper">
<a href="<?php echo get_post_meta( $post->ID, 'URLThumb', true ); ?>">
<?php
/**
* woocommerce_before_shop_loop_item_title hook
*
* @hooked woocommerce_show_product_loop_sale_flash - 10
* @hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' );
?>
</a>
</div>
Here is the thumbnail function that I can't seem to drill down further to find the existing <a href="<?php the_permalink(); ?>">
to change. This is on the woocommerce-template.php page.
if ( ! function_exists( 'woocommerce_template_loop_product_thumbnail' ) ) {
/**
* Get the product thumbnail for the loop.
*
* @access public
* @subpackage Loop
* @return void
*/
function woocommerce_template_loop_product_thumbnail() {
echo woocommerce_get_product_thumbnail();
}
}
Figured out a work around. Since the SalesFlash image was the one being triggered, I just used a blank PNG image to overlay ontop of the product image. Turned all my products into sale items and it works. Not perfect, but I don't need the sale icon anyway.
But if anyone does know of a proper programming solution, I would change it. Thanks.
File Name: woocommerce.php
File Location: wp-content/themes/'your-theme'/theme/woocommerce.php
Solution: Target external products via query of product type, looping in $product_url when external, and looping in get_permalink() when simple/variable. This code also accounts for opening external products in a new tab.
I'm going to post one version of what the code looked like before, and then another with my additions + modifications. In my theme, the first line of code I pasted exists on line 374 within woocommerce.php (this will differ depending on your theme, and some themes may not have a modified woocommerce.php file. If that is the case, just drag woocommerce.php into your theme directory from the plugin.
Code Before Addition/Modification:
Code After Addition/Modification:
Code Added:
Code Modified:
With the exception of the code that was added above, replace all instances of get_permalink() with $product_url.
this on worked for me in the content-product.php without asking the meta data