【问题标题】:Remove "product-category" from WooCommerce but only on first level从 WooCommerce 中删除“产品类别”,但仅在第一级
【发布时间】:2021-07-12 11:27:26
【问题描述】:

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

首页 > 分类 > 子分类

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

提前致谢。

【问题讨论】:

    标签: wordpress woocommerce breadcrumbs


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      相关资源
      最近更新 更多