简体   繁体   English

woocommerce 将类别导航添加到产品类别页面或动态页面

[英]woocommerce add category nav to product-category pages or dynamic pages

I have the product categories navbar on top of the shop page.我在商店页面顶部有产品类别导航栏。 If I click on any of the category navbar, then it take me to the product-categories page, however, on top of this page, the categories navbar are unavailable.如果我单击任何类别导航栏,则会将我带到产品类别页面,但是,在此页面顶部,类别导航栏不可用。 I need to embed this product category navbar to the product-categories pages too.我也需要将此产品类别导航栏嵌入到产品类别页面中。 I'm unable to add shortcodes [product_categories] because, the product-categories page is dynamic ie based on the filters.我无法添加短代码 [product_categories] 因为产品类别页面是动态的,即基于过滤器。 I've played with customize>woocommerce>shop page display & category display but nothing worked.我玩过自定义>woocommerce>商店页面显示和类别显示,但没有任何效果。 Any assistance on this is much appreciated.非常感谢您对此的任何帮助。 Attached screen shot reference.附上截图参考。

在此处输入图像描述

在此处输入图像描述

You can use WooCommerce hooks.您可以使用 WooCommerce 挂钩。 for example例如

function filter_woocommerce_catalog_orderby( $array ) { 
    



  $taxonomy     = 'product_cat';
  $orderby      = 'name';  
  $show_count   = 0;      // 1 for yes, 0 for no
  $pad_counts   = 0;      // 1 for yes, 0 for no
  $hierarchical = 1;      // 1 for yes, 0 for no  
  $title        = '';  
  $empty        = 0;

  $args = array(
         'taxonomy'     => $taxonomy,
         'orderby'      => $orderby,
         'show_count'   => $show_count,
         'pad_counts'   => $pad_counts,
         'hierarchical' => $hierarchical,
         'title_li'     => $title,
         'hide_empty'   => $empty
  );
 $all_categories = get_categories( $args );
 foreach ($all_categories as $cat) {
    if($cat->category_parent == 0) {
        $category_id = $cat->term_id;       
        echo '<br /><a href="'. get_term_link($cat->slug, 'product_cat') .'">'. $cat->name .'</a>';

        $args2 = array(
                'taxonomy'     => $taxonomy,
                'child_of'     => 0,
                'parent'       => $category_id,
                'orderby'      => $orderby,
                'show_count'   => $show_count,
                'pad_counts'   => $pad_counts,
                'hierarchical' => $hierarchical,
                'title_li'     => $title,
                'hide_empty'   => $empty
        );
        $sub_cats = get_categories( $args2 );
        if($sub_cats) {
            foreach($sub_cats as $sub_category) {
                echo  $sub_category->name ;
            }   
        }
    }       
}

    
    return $array; 
}; 
         
// add the filter 
add_filter( 'woocommerce_catalog_orderby', 'filter_woocommerce_catalog_orderby', 10, 1 ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为产品类别替换 Woocommerce 单一产品页面上的“添加到购物车”按钮 - Replace Add to cart button on Woocommerce Single Product Pages for a product category WooCommerce-在哪里更改“产品类别”路径? - WooCommerce - where to change 'product-category' path? 在Woocommerce产品类别归档页面上禁用“添加到购物车”按钮 - Disable add to cart button on Woocommerce product category archive pages 为 WooCommerce 类别存档页面添加产品标题标签 - Add product title heading tag for WooCommerce category archive pages 仅显示特定类别的WooCommerce产品页面 - Show WooCommerce product pages for only specific category Woocommerce 管理页面中的产品类别分类 - Woocommerce Product Category taxonomy in Admin Pages Woocommerce 分页产品类别页面的条件标记 - Conditional tag for Woocommerce paged product category pages WooCommerce-如何从网址中删除产品和产品类别? - WooCommerce- How to remove product & product-category from urls? 从子类别术语中定位 WooCommerce 产品类别存档页面 - Target WooCommerce product category archive pages from a child category term Woocommerce面包屑,用单个产品页面上的页码替换产品类别 - Woocommerce Breadcrumbs, Replace Product Category with Page Number on Single Product Pages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM