How to get current product category name in woocommerce?

Member

by adan , in category: PHP CMS , 6 months ago

How to get current product category name in woocommerce?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by denis , 6 months 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.