//Customize Woocommerce Category Widget to show title of current category
function dynamic_product_category_widget($title, $widget_instance, $widget_id) {
if ( $widget_id !== 'woocommerce_product_categories' )
return $title;
if ( is_product_category() ) {
$cat_title = '<p class="widget-title footer-widget">'.single_cat_title()."</p>";
return $cat_title;
} elseif ( is_product() ) {
$cat = get_the_terms( $product->ID, 'product_cat' );
foreach ($cat as $categoria) {
if($categoria->parent == 0){
$topCategory = $categoria;
}
}
return '<p class="widget-title footer-widget">'.$topCategory->name.'</p>';
}
return $title;
}
add_filter ( 'widget_title' , 'dynamic_product_category_widget', 10, 3);
Here you go for 2022!
//Customize Woocommerce Category Widget to show title of current category
function dynamic_product_category_widget($title, $widget_instance, $widget_id) {
if ( $widget_id !== 'woocommerce_product_categories' )
return $title;
if ( is_product_category() ) {
$cat_title = '<p class="widget-title footer-widget">'.single_cat_title()."</p>";
return $cat_title;
} elseif ( is_product() ) {
$cat = get_the_terms( $product->ID, 'product_cat' );
foreach ($cat as $categoria) {
if($categoria->parent == 0){
$topCategory = $categoria;
}
}
return '<p class="widget-title footer-widget">'.$topCategory->name.'</p>';
}
return $title;
}
add_filter ( 'widget_title' , 'dynamic_product_category_widget', 10, 3);