I have a website built on the Ample Business theme with the Woocommerce plugin installed and activated. We have created a custom shop page and want to redirect the Woocommerce /shop/ URL to the new page. I have read several posts that prescribe answers, but none seem to work. The page will not redirect.
What I’ve tried:
Added the following code to the child theme’s functions.php file:
// Redirect WooCommerce Shop URL
function wpc_shop_url_redirect()
{ if( is_shop() ){
wp_redirect( home_url( '/shop2/' ) ); // Assign custom internal page here exit(); } }
add_action( 'template_redirect', 'wpc_shop_url_redirect' );
Tried a standard 301 redirect via .htaccess.
These solutions do not work and I can not simply create a new template file for archive_product.php because all Woocommerce files reside in the plugins folder as opposed to the theme folder. I do not want the file overwritten with each update.
Any suggestions would be greatly appreciated.
2
Answers
I figured it out. The issue was that I inadvertently had the parent theme activated and was editing the child theme's functions.php file. The following code added to functions.php successfully redirects the shop page:
First, create a
shop2
page. then create Page Templates then assign WordPress page template to pageshop2
page.Below is the example template file look like. you can give this file name like
template-shop2.php
Then you can use your
template_redirect
and redirect to yourshop2
. this code will go in your active theme functions.php file.