将WooCommerce 'Shop'页面转发到网站上的其他页面



作为我们站点地图的一部分(使用WooCommerce),我们不想在/shop/有一个页面。相反,我们的菜单只是直接链接到商店类别。因此,我想使用PHP将/shop/转发到我们的主要类别,即/product-category/coffee/。

在以前的Wordpress站点上,我使用了类似于下面的东西,在一个专门的页面模板文件中转发用户。但是,在模板名称"page-shop.php"中使用下面的代码不起作用,我留下了一个通用的"商店概述页面",显示类别和产品。

是代码错误还是我把它放在错误的模板内?

感谢
<?php
/* Redirect /shop/ directly to coffee category */
wp_redirect( get_bloginfo('url').'/product-category/coffee/' ); exit;
?>

尝试将以下代码放入主题的functions.php文件。

function custom_shop_page_redirect() {
    if( is_shop() ){
        wp_redirect( home_url( '/product-category/coffee/' ) );
        exit();
    }
}
add_action( 'template_redirect', 'custom_shop_page_redirect' );

最新更新