-
-
Save jaygidwitz/1823672894bc65a0744cb043d107b771 to your computer and use it in GitHub Desktop.
<?php // Do not include this if already open! | |
/** | |
* Code goes in theme functions.php. | |
*/ | |
add_action( 'template_redirect', 'redirect_external_products' ); | |
function redirect_external_products() { | |
global $post; | |
if ( is_singular( 'product' ) && ! empty( $post ) && ( $product = wc_get_product( $post ) ) && $product->is_type( 'external' ) ) { | |
wp_redirect( $product->get_product_url() ); | |
exit; | |
} | |
} |
Thanks for the plugin, @jaygidwitz However, I already have over 30 plugins on the site and actively trying to get the site to better perform speed-wise. So unfortunately another plugin is not really an option. The best option is to input the code. Am I correct that having it open in a new window is as simple as adding " target="_blank"> somewhere?
Any chance you can insert that code for me, @jaygidwitz ? Would be great for these items to open in a new window.
Hi @VickyTFC,
You'd need to use either a plugin or a template override in the theme.
You might be able to ask someone in the WPBeginner Facebook group, as the plugin I mentioned was the easiest way I found so far. I don't think you'd have significant speed improvements with either method, and the more complexity you introduce the more code you'd need to maintain in the future.
So that plugin, which is maintained by another developer might be better for you than having to maintain your own code via you or your own developer from a time/cost point of view.
If you're having speed issues with only over about 30 plugins it might actually be a hosting issue, and you might be better served by finding a speedier host, depending on exactly what's going on with the site.
I hope this helps!
Hi @jaygidwitz this code works great. Thank you!! Any chance you can advise how it can open in a new window please? Thanks, Vicky