[英]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.