WooCommerce: Display Category Name
Asked Answered
D

4

13

Is there a way to display the product category name on the WooCommerce archive-product.php page.

My product category name is "Bracelets", and I'd like that to be displayed as a title on the page.

I'm using wp_title() currently:

<h1><?php wp_title(); ?></h1>

But that prints it to the page like this:

» Product Categories » Bracelets

I'm getting the parent page title and the catgeory name with separators in between them (above).

Is there any way I can get the title to print just "Bracelets"?

Any help with this is appreciated.

Thanks in advance!

Danford answered 4/11, 2014 at 22:50 Comment(0)
M
33

You're looking for single_term_title():
https://developer.wordpress.org/reference/functions/single_term_title/

Montsaintmichel answered 4/11, 2014 at 23:4 Comment(0)
P
8

Currently you can display product categories this way (Wordpress 4.x):

<?php echo wc_get_product_category_list($product->get_id()) ?>
Preemption answered 19/12, 2017 at 20:6 Comment(1)
If, for some reasons, you need to display the category name without the link : <?php $current_cat = strip_tags(wc_get_product_category_list($product->get_id())); echo $current_cat; ?>Incarnate
I
5

Use the get_categories function to retrieve categories name :-

You can use this code to display product categories name -

<?php global $post, $product;
    $categ = $product->get_categories();
    echo $categ; ?>
Isometrics answered 29/6, 2016 at 6:36 Comment(1)
I downvoted because this method is obsolete since Wordpress 3.0. In 2019 you should definetely use @Igor Okto below answer <?php echo wc_get_product_category_list($product->get_id()) ?>Nievesniflheim
B
0

I think it prints the breadcrumb, because it's hooked woocommerce_breadcrumb.

You could override in your theme the template Archive-product.php

<?php
    /**
     * woocommerce_before_main_content hook
     *
     */
    do_action( 'my_woocommerce_before_main_content' );
?>

and create another action inside functions.php,

add_action( 'my_woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
add_action( 'my_woocommerce_before_main_content', 'my_woocommerce_print_category_name', 20 );

Inside your functions.php you can also create a functions like this:

function my_woocommerce_print_category_name() {
    //You can implements a function for get category name...    
}
Basia answered 4/11, 2014 at 23:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.