我用WooCommerce销售单一产品,所以我没有商店基础页面。现在我已经将产品帖子添加到我的主菜单中,但我想实际使用产品短代码在正常页面上显示完整的单个产品[product_page_ID="99"],以便我可以轻松地向其添加其他内容,并将此页面添加到我的菜单中。但是我最终还是会看到内容基本相同的单一产品帖子(可以在…/shop/product下访问),我该如何避免这种情况?
创建一个新页面,并添加以下短代码[product_page id="123"]
(用有效的产品ID替换123),根据需要添加额外的内容,然后将页面添加到您的菜单。
但是我最终还是会得到一个内容基本相同的产品帖子(可以在…/shop/product下访问),我怎么才能避免这种情况呢?
在你的另一个线程上,我为你提供了一些关于重定向商店基地的代码,你需要修改它,以还包括单个产品页面,这是更新的版本:
add_action( 'template_redirect', 'redirect_shop' );
function redirect_Shop() {
// added is_product() conditional to stop users from accessing the single product page
if( is_shop() || is_product() ) {
//replace the link below to point to your custom product page
header('HTTP/1.1 301 Moved Permanently');
header('location:http://www.example.com/page');
exit;
}
}