A BloomerArmada fan asked me a very interesting question: how can I link each product in the shop page to its own custom landing page as opposed to the default permalink?
Of course this applies when you don’t want to use the default single product page for all or some products. Clearly, you could set up a 301 redirect from the single product page to the landing page – that will help for SEO as well. But if this is temporary, or you need to still give access to the single product page later on, then a redirect is no good.
So, here’s how you can override the default permalink.
PHP Snippet: Change Product Links @ WooCommerce Shop / Loop Pages
Thankfully, the woocommerce_template_loop_product_link_open() function, which is responsible for the product “a href” in the loop pages, contains a filter called woocommerce_loop_product_link
You can therefore change that link with add_filter() and return your custom URL instead of the default permalink.
It even gives you access to $product, which means if you have the custom URL saved in a custom field, you can return that programmatically.
/**
* @snippet Change Product Permalinks @ WooCommerce Shop
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @compatible WooCommerce 4.0
* @donate $9 https://tutoraspire.com
*/
add_filter( 'woocommerce_loop_product_link', 'tutoraspire_change_product_permalink_shop', 99, 2 );
function tutoraspire_change_product_permalink_shop( $link, $product ) {
$this_product_id = $product->get_id();
// E.G. CHANGE LINK FOR PRODUCT ID = 25
if ( $this_product_id === 25 ) $link = '/custom-landing-page';
return $link;
}