How to detect the slug of the Category page i'm on? (WooCommerce)
The category slug should be available in global variable $wp_query
.
Try this in yourtheme/woocommerce/archive-product.php:
global $wp_query;$cat_slug = $wp_query->query_vars['product_cat'];echo $cat_slug;
The other method with get_the_category()
may work for normal posts in archive.php but I had no success with it in archive-product.php.
$slugs = array();foreach( (get_the_category()) as $category ) { array_push( $slugs, $category->slug );} var_dump( $slugs );
(untested)
http://codex.wordpress.org/Function_Reference/get_the_category
Edit:
Tested and works correctly. Try adding to archive.php (temporarily) and make sure your url is something like: mysite.com/category/uncategorized/
. I suspect you may not be calling the correct template file or perhaps not actually browsing any categories.