How to get current product category name in woocommerce?

Member

by adan , in category: PHP CMS , a year ago

How to get current product category name in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , a year ago

@adan 

To get the current product category name in WooCommerce, you can use the following code snippet:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
global $wp_query;

// Get current product category
$term = $wp_query->get_queried_object();

// Get category name
$category_name = $term->name;

// Display category name
echo $category_name;


You can add this code to your theme's functions.php file or create a custom plugin to use it. This code will fetch the current product category name that is being viewed on a product category archive page and then display the category name.

Related Threads:

How to remove product-category from urls in woocommerce?
How to get category id from category name in discord.js?
How to show product parent category in woocommerce?
How to change product category slug in bulk in woocommerce?
How to get category name in Magento 2?
How to add a category programmatically to a woocommerce product?