woocommerce link to external product

Woocommerce link to external product

(Warning: I’m not a programmer) Straight to the point.

I have a product catalogue http://adidassuperstar.cz, and I want images (thumbnails) point to the affiliate link – the same link as the link of a buy button under the image.

I googled everything, but none of the answers actually worked for me. However, I found something which helped me just half the way. When I insert this code to functions.php it makes this: Every link point to the affiliate link – I mean even a title of a product. I want only the image to have an affiliate link, not the title. The title should point to the product page on my site.

Here is the code:

I only need to specify the code to redirect only images (thumbnails). If you have a clue how to do that. Please let me know.

*Additional info (changed 6.12.2016):

I use a WordPress theme: Avada

Products was imported with plugin: WP All import

If you need any more information, I will give it to you. Just ask 🙂

WooCommerce uses a template for those images. They are product-thumbnails.php and ‘product-image.php’ files located in single-product folder in your WooCommerce templates folder.

For me these files are located in theme/woocommerce/single-product/ and "theme" is your theme (in this case Avada).

Based on what your theme does to WooCommerce templates (some themes rewrite them completely) you can just change some of those template files directly and add your links.

But the cleaner way would be to use actions that are used widely in WooCommerce and add your link to the images using them. The way I see it in an older version of Avada the themes modifies ‘woocommerce_single_product_image_html’ filter hook which shows the product main image.

If you share the files product-thumbnails.php and product-image.php with us we could find an easy solution.

I personally don’t have access to your themes to see what exactly it does with images.

Change the default WooCommerce External Product Button

This is an Ask SkyVerge question from Manuel:

How can I change the add to cart button for external products? I need to use something besides “Buy product” for my external products.

The good news here is that there’s already a setting for your WooCommerce external products to change the button text. When you edit the product, you can enter the button text while creating it, right after you enter the product link.

This will adjust the button on your product page to use the entered text instead:

This button will also be adjusted on the shop page and category pages.

If you don’t set the button text manually here, the default “Buy product” text will be used instead.

Modify Default button text

So what if you want to modify that default text instead so you don’t have to change every single button’s text while creating external products? There’s a really useful filter in place that we can use here to change this text instead.

The woocommerce_product_single_add_to_cart_text filter will let us filter the add to cart button text for our products, which is used in both archive loops and on the single product page.

However, we can’t just blindly change this button:

As this would change the button for all products in the store. Instead, we want to scope this change to only external products. We can do so with a tiny bit more code to check the product type before changing the button.

Now we’re cooking �� This snippet adds a few nice tweaks for us:

  • If the product is an external product, the default text is now “Buy at Amazon” instead of “Buy product”.
  • Other product types will use their default button text, as it’s unchanged
  • Since we check if button text is set before using the default, you can still manually set button text for some products as desired.

Now the default behavior is changed for the WooCommerce external product button text, but it can still be overridden using the product settings.

How to Get WooCommerce External Product Links to Open in a New Tab

It’s an age-old argument. Should a page open in a new tab in your browser or not?

I’m not here to argue. I’m going to leave that decision to the WooCommerce store owner. But if someone is on your store and they click on an external link, this might be the option you prefer.

Let’s step back a moment. What are external links in WooCommerce? Well, they are a product type. You can choose to add products that might be affiliate links or products via a site like Amazon.

This is another way of monetizing your site. We do this over on BobWP.shop.

By default, when someone clicks on a product that is created using this product data, it opens in the same window.

But what if you want all WooCommerce external links to automatically open in a new window?

And when I say easy, I mean easy. All you have to do is install and activate the plugin. And it will do its magic.

How to Open Only Specific External Products

But what if you want this to work only on specific external products and not on every single external product you have set up?

Well, there is a free plugin for that called WooCommerce Improved External Products. And if you need even more control, they have a premium version with the option to not only open external products in new tabs, but also for those product archives, as well as setting it based on a category. So it will just cost you a few bucks to get more control over your links.

This is one of those issues that people usually have strong opinions, on one side or the other. Myself, when I’m browsing, I prefer a new tab rather than clicking that back arrow one, two or several times. But that’s just me. I’m not here to make an argument about opening new tabs, but simply to give you a couple of possible solutions.

Leave a Reply

Your email address will not be published. Required fields are marked *