wordpress - 从 WooCommerce 中删除“产品类别”,但仅在第一级
问题描述
有没有办法从 WooCommerce 的面包屑中删除“产品类别”位,但问题是只在第一级进行。例如:
首页 > 分类 > 子分类
“product-category”位只需要从上述面包屑中的“Category”部分中删除,而不需要从“Sub-Category”部分中删除。
提前致谢。
解决方案
您可以使用此过滤器删除第一级产品类别
// change the breadcrumb on the product page
add_filter( 'woocommerce_get_breadcrumb', 'custom_breadcrumb', 20, 2 );
function custom_breadcrumb( $crumbs, $breadcrumb ) {
// only on the single product page
// if ( ! is_product() ) {
// return $crumbs;
// }
//get product details
//global $product;
//for print array
// print_r($crumbs);
//die;
// remove the first element of the array "$crumbs"
unset($crumbs[1]);
return $crumbs;
}
推荐阅读
- java - 为什么在将 json 文件读入我的对象后得到 NPE?
- java - 单击锚标记时如何从mysql表中检索数据
- graphql - Apollo useQuery() - 如果响应相同,则忽略“refetch”
- c# - “public static void Main()”和“public static void Main(String[] args)”有什么区别?
- git - 为什么我用不同PC上的某个帐户推送到Github时“Open a pull request”会提示出现
- scala - 如何在 flink kafka 流中使用 sql?
- python - 列表内列表之间的欧几里德距离
- python - 避免 pip 和 conda 的组合
- javascript - 请帮助理解功能
- javascript - 通过 mysql npm 包进行更新时出错