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);
Related Posts:
- Woocommerce add to simple product attribute programmatically [closed]
- How to customize search result page title?
- Creating loop within functions.php
- Set quantity of woocommerce product on page visit [closed]
- How can I remove the main description text box in a Woocommerce product editor page? I only use the “Product short description” text box [closed]
- When sale price is 0.00 show only regular price
- Create custom function for hero image
- Remove text after a dot and a colon in Woocommerce product title
- Woocommerce custom calculation function
- Display page number on custom page title function
- Copy and Modified WooCommerce function is_coupon_valid [closed]
- Issues with title-tag and document_title_parts
- How to create a custom order status in woocommerce!
- When should you, and when should you not, use wp_list_pluck()?
- How to show product SKU on product page
- How to get woocommerce inventory status [closed]
- opening links in new tab using – add_filter( ‘the_content’, ‘make_clickable’);
- In WooCommerce I need to modify the thankyou.php page [closed]
- Set default options for inserting media
- Remove tag on my RSS Feed
- Remove product description from product archive page
- display 100 products per page on product category page [closed]
- Adding WooCommerce to a Custom Theme – not working [closed]
- Can you use admin pages functionality on the frontend of your site
- Theme-Config tab in admin Pannel?
- How to Add a Random Custom Gravatar in the WordPress Comments?
- Override woocommerce wc-class function
- Display WooCommerce subscriptions for user [closed]
- Increment price for Woocommerce Minicart [closed]
- Change woocommerce products weight varation based its product category or tags? [closed]
- How to mass-delete inline styles in WordPress custom post type automatically?
- Remove the deleted users avatar from list
- Woocommerce checkout field maxlength, make input number field only (postcode)
- PHP files included in functions.php don’t seem to work
- How Can I Expand the WordPress Customize window without any Plugin?
- str_replace function in theme
- Calling a function from anywhere, used in different places
- How to display custom option field in woocommerce orders in admin panel?
- Best practices regarding the creation of custom widgets?
- How to add a slide toggle to the Woocommerce-Layout__Activity-Panel area in the orders admin page
- Is possible add icon in title posts only in specific tag?
- How to auto refresh when user change postcode
- Word Press – Dynamic Content [closed]
- how can I just add to parent theme function(s) instead of redeclaring whole the function
- woocommerce change currency per category [closed]
- How to override woocommerce.css?
- How can I use Woocommerce $product->get_attribute in functions.php? (if at all)
- How to change this simple code so that it sends the email notification after payment in WooCommerce?
- Function extending with if query in functions.php
- Woocommerce checkout field
- add referrer to woo
- Add attribute only to first image of every post via functions.php
- The_content and Preg_replace in loaded Iframe [closed]
- Create a Woocommerce product widget with category filter
- Auto scroll to id on page load on all pages except home page. Only do this on mobile
- Adding product to WooCommerce cart [closed]
- Change WooCommerce add_to_cart Button Text?
- two search forms on the same page
- WooCommerce -> wc_enqueue_js not working [closed]
- Use existing image sizes for WooCommerce
- Insert a field with PREG_REPLACE – strange behaviour
- New checkbox in custom widget isn’t saving data
- how to display a page before the home page
- Function to check if custom page is used by page?
- Woocommerce Variable Product Dropdown for Custom Shop Template
- Woocommerce Default sorting product by product type
- How to remove font awesome from loading in wp theme
- Change class woocommerce on function.php
- Header menu aligned right on all pages except for single-post page [closed]
- Hide ‘add to cart’ when certain value in dropdown is selected
- Adding discount functionality to the cart
- How to get the full product name by ignoring custom modification on it
- Hide author info in single posts by certain users
- price of product can’t return when get data of product in functions.php
- Woocommerce product price change
- Help with with my function for wordpress
- Remove clickable Link of WordPress Site Logo from Woocommerce Single Product page
- Shortcode to insert default text and change one word throughout it?
- I want to customize the_posts_navigation function by replacing prev and next with images
- Woocommerce – Switching Price for Category
- How would I correctly implement a new if statement in a child functions file?
- Echo a String Based On Geolocation? [Woocommerce || ACF]
- Move product attributes after summary on single product page
- Show number of sold products but be first for less than 2
- True email confirmation for registration (keeping unvalidated users from user table)
- function syntax is off,
- Adding A New Widget to WordPress Disables the Existing Widgets
- How To Show Shortcodes In WordPress Custom Fields?
- How do I integrate my Child Theme into a Custom Template?
- Shortcode to eliminate and replace with
- custom post with loading script per single post
- Force changing the Site Title and add link
- Get Value of Custom Field
- restrict access to specific urls on a specific period of time
- child_of not working while searching
- Get term count on a category page
- Removing Facebook contact field from user contact not working
- add variable to actions/functions across different files (woocommerce)
- How do I add functionality to images?
- How to crop image in WordPress with aspect ratio for any size of image