I'm really not a developer, but this is something I expect not to be too hard to achieve :-) I really don't know where to start, so that's point 1. I read all of the topics about dynamically changing the widget title, but they all need human interaction.

Maybe I'm thinking too simple, but wouldn't it be easy to replace the default WOOCommerce Widget title (ie. "Product categories") by the parent category title?

Let's say that I'm browsing through the category "Nike" where I'm viewing products or categories, and the sub-categories are showing in the widget (ie. Shoes, Shirts, etc.). In this case the widget title "Product categories" should show "Nike" as widget title.

Could you help me getting it up and running?


Try this it works for me. Place this code in your theme functions.php file.

function dynamic_product_category_widget($title, $widet_instance, $widget_id) {

    if ( $widget_id !== 'woocommerce_product_categories' )
        return $title;

    if ( is_product_category() ) {
        $cat_title = single_cat_title('<p class="widget-title footer-widget">', '</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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.