This snippet stops the user from being able to the view the single product template and instead redirects them to a user defined URL. In this specific example, we redirect users to our guides page if they try to view any product page. This may be useful if you require customers to fill out a form, login to their account, or complete some other action before being able to view a product.
/**
* Snippet Name: ecommercehints.com
* Snippet Author: WooCommerce Redirect Product Links On Product Archive
*/
add_action( 'template_redirect', 'ecommercehints_redirect_product_links', 10 );
function ecommercehints_redirect_product_links() {
if (!is_product()) return;
wp_redirect( 'https://ecommercehints.com/guides' ); // redirect to this URL.
exit();
}