php - 从 Woocommerce 产品搜索结果页面中删除跟踪
问题描述
更具体地说,在我之前的问题中,我想实现以下目标:
我正在使用 Woocoomerce 并删除了主商店页面,因为我只有产品类别并且只需要这些页面。除了产品搜索结果页面(Woocommerce 产品搜索小部件的结果显示页面)之外,所有面包屑都正确显示,没有“商店”踪迹(因为我已删除该页面)。此页面显示以下面包屑:
“首页/产品/搜索结果...”
这是唯一一个仍然在其中显示跟踪“产品”的 Woo 页面(这是默认行为,我已经用二十七号在新的一期中进行了测试),我需要删除它。有趣的是,当主商店页面没有被删除时,产品搜索结果页面的面包屑看起来是这样的:
“首页/商店/搜索结果...”
所以我的目标真的是像这样在搜索结果页面上有面包屑
“首页/搜索结果...”
谢谢!
解决方案
我遇到了同样的问题,我通过将 WooCommercebreadcrumb.php
复制到 来覆盖它mytheme/woocommerce/global/breadcrumb.php
,运行 ais_search()
以确定我是否在搜索结果中,然后array_splice
是元素。
<?php
/**
* Shop breadcrumb
*
* This template can be overridden by copying it to yourtheme/woocommerce/global/breadcrumb.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @version 2.3.0
* @see woocommerce_breadcrumb()
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! empty( $breadcrumb ) ) {
echo $wrap_before;
if ( is_search() ) {
array_splice( $breadcrumb, 1, 1 ); // considering that the element is at the second position.
// Otherwise :
// array_splice( $breadcrumb, 0, 1 ); if it's at the first position, etc.
}
foreach ( $breadcrumb as $key => $crumb ) {
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
} else {
echo esc_html( $crumb[0] );
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
echo $delimiter;
}
}
echo $wrap_after;
}
你也可以
...
foreach ( $breadcrumb as $key => $crumb ) {
// Ignore the "Product" item
if ( $crumb[0] == 'Product' ) {
continue;
}
echo $before;
if ( ! empty( $crumb[1] ) && sizeof( $breadcrumb ) !== $key + 1 ) {
echo '<a href="' . esc_url( $crumb[1] ) . '">' . esc_html( $crumb[0] ) . '</a>';
} else {
echo esc_html( $crumb[0] );
}
echo $after;
if ( sizeof( $breadcrumb ) !== $key + 1 ) {
echo $delimiter;
}
}
...
推荐阅读
- sql-server - 如何将 T-SQL CTE 查询中的唯一标识符 ID 组合成字符串
- python - 在 Python 中使用 Pandas 使用其 URL 导入 CSV 文件
- c# - 如何将循环文本框传递给 ASP.NET MVC 中的控制器变量
- python - 'Builtin_function_or_method' 对象不可下标。使用 NumPy 时出错
- visual-studio-code - Visual Studio Code - 从 NPM 脚本资源管理器中排除子目录
- angular - Angular http 请求在 Chrome 中正确返回 Observable 数组,但在 Internet Explorer 中为空数组
- python - 为什么 sklearn OneHotEncoder 不能与单个数据框列一起使用?
- c# - Microsoft Graph:无法更新事件的开始或结束日期
- c# - 字符不在水平轴上移动
- c# - C# .NET 图像未显示在本地资源中