skip to Main Content

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


  1. Chosen as BEST ANSWER

    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:

    // Redirect WooCommerce Shop URL
    function wpc_shop_url_redirect() {
        if( is_shop() ){
            wp_redirect( home_url( '/store/' ) ); // Assign custom internal page here
            exit();
        }
    }
    add_action( 'template_redirect', 'wpc_shop_url_redirect' );
    

  2. First, create a shop2 page. then create Page Templates then assign WordPress page template to page shop2 page.

    Below is the example template file look like. you can give this file name like template-shop2.php

    <?php 
    
        /* Template Name: Example Template */ 
    
        get_header();
    
        // your product display code.
    
        get_footer();
    
    ?>
    

    Then you can use your template_redirect and redirect to your shop2. this code will go in your active theme functions.php file.

    function custom_shop_page_redirect() {
        if( is_shop() ){
            wp_redirect( home_url( '/shop2/' ) );
            exit();
        }
    }
    add_action( 'template_redirect', 'custom_shop_page_redirect' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search