php - 完全禁用 WooCommerce 商店页面,但保留搜索页面
问题描述
我对 WooCommerce 有疑问。我想完全禁用商店页面,但我仍然希望用户能够搜索产品。
这就是我现在所拥有的——它可以工作,但它也禁用了搜索页面,因为它使用了商店页面。
function woocommerce_disable_shop_page() {
global $post;
if (is_shop()):
global $wp_query;
$wp_query->set_404();
status_header(404);
endif;
}
add_action( 'wp', 'woocommerce_disable_shop_page' );
希望你能帮忙。
解决方案
我刚刚修改了您问题中的代码并且它正在工作。请在主题functions.php
文件或自定义插件文件中添加以下代码。
function woocommerce_disable_shop_page() {
global $post;
if (is_shop() && !(is_search())):
global $wp_query;
$wp_query->set_404();
status_header(404);
endif;
}
add_action( 'wp', 'woocommerce_disable_shop_page' );
推荐阅读
- c# - 使用 VLC 流式传输图像或桌面屏幕(LibVLCSharp for WPF)
- c# - 实现 IAsyncEnumerable 的空 IQueryable
- react-native - 通过 React Native 的 Axios 发布调用会导致云 url 的网络错误适用于 ios 而不适用于 android
- postgresql - 致命:用户“postgres”的密码验证失败。无法连接
- html - 大写后的文本小写是可能的吗?
- django - 如何在投票系统的 Django 数据库中增加投票字段
- php - 如何在 Laravel 中更新数据库记录
- reactjs - 无法在反应 redux 项目的返回函数中使用查找函数
- c# - WPF 应用程序正在使用大量 GPU 功能
- design-patterns - 如何处理我的有效负载以在 cassandra 中具有原子性/一致性的多个表中插入批量数据?