停用 WooCommerce 商店基地
Deactivate WooCommerce shop base
由于我只使用 WooCommerce 销售一种产品,因此我想删除商店库。我已经删除了 WooCommerce 在安装时自动设置的页面 "shop",但是您仍然可以通过输入 .../shop 来访问商店基本页面。
我知道要完全停用它,我需要将第 264 行设置为 false:
https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-post-types.php#L264
不过我对编程还很陌生,谁能告诉我该怎么做?
您的站点中不需要 archieve.php
模板,因此可以限制此模板的执行,正如@Anand Shah 所说,您还可以显示内容 if ( !is_shop() )
,这意味着当页面不是 shop.how 您想要完成的,这很重要,有很多方法可以做到这一点。
在您引用的行上方几行,您可以看到注册产品 post 类型的所有参数都通过 woocommerce_register_post_type_product
过滤器发送,这意味着您可以修改任何的价值观。要禁用 shop
存档,您需要从新插件或主题的 functions.php(不太理想)中将 has_archive
设置为 false。
add_filter( 'woocommerce_register_post_type_product', 'so_32921498_product_post_type_args' );
function so_32921498_product_post_type_args($args){
$args['has_archive'] = false;
return $args;
}
将以下代码添加到您子主题的 functions.php 文件
add_action( 'template_redirect', 'redirect_shop' );
function redirect_shop() {
if( is_shop() ) {
//replace the link below to point to your single product page
header('location:http://www.example.com/');
exit;
}
}
由于我只使用 WooCommerce 销售一种产品,因此我想删除商店库。我已经删除了 WooCommerce 在安装时自动设置的页面 "shop",但是您仍然可以通过输入 .../shop 来访问商店基本页面。
我知道要完全停用它,我需要将第 264 行设置为 false: https://github.com/woothemes/woocommerce/blob/master/includes/class-wc-post-types.php#L264
不过我对编程还很陌生,谁能告诉我该怎么做?
您的站点中不需要 archieve.php
模板,因此可以限制此模板的执行,正如@Anand Shah 所说,您还可以显示内容 if ( !is_shop() )
,这意味着当页面不是 shop.how 您想要完成的,这很重要,有很多方法可以做到这一点。
在您引用的行上方几行,您可以看到注册产品 post 类型的所有参数都通过 woocommerce_register_post_type_product
过滤器发送,这意味着您可以修改任何的价值观。要禁用 shop
存档,您需要从新插件或主题的 functions.php(不太理想)中将 has_archive
设置为 false。
add_filter( 'woocommerce_register_post_type_product', 'so_32921498_product_post_type_args' );
function so_32921498_product_post_type_args($args){
$args['has_archive'] = false;
return $args;
}
将以下代码添加到您子主题的 functions.php 文件
add_action( 'template_redirect', 'redirect_shop' );
function redirect_shop() {
if( is_shop() ) {
//replace the link below to point to your single product page
header('location:http://www.example.com/');
exit;
}
}