首页 > 解决方案 > 从 WooCommerce 中删除“产品类别”,但仅在第一级

问题描述

有没有办法从 WooCommerce 的面包屑中删除“产品类别”位,但问题是只在第一级进行。例如:

首页 > 分类 > 子分类

“product-category”位只需要从上述面包屑中的“Category”部分中删除,而不需要从“Sub-Category”部分中删除。

提前致谢。

标签: wordpresswoocommercebreadcrumbs

解决方案


您可以使用此过滤器删除第一级产品类别

// 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;
}

推荐阅读