WooCommerce: Show category name

Is there a way to display the name of the product category on the WooCommerce archive-product.php page. The name of my product category is “Bracelets,” and I would like it to appear as the title on the page. I am using wp_title() currently:

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

But this prints it on the page as follows:

 » Product Categories » Bracelets 

I get the title of the parent page and the name category with separators between them (see above). Is there a way to get the title for printing only “Bracelets”?

Any help with this is appreciated.

Thanks in advance!

+6
source share
4 answers

You are looking for single_term_title() : http://codex.wordpress.org/Function_Reference/single_term_title

+15
source

Use the get_categories function to retrieve category names: -

You can use this code to display product category names -

 <?php global $post, $product; $categ = $product->get_categories(); echo $categ; ?> 
+1
source

I think he prints a piece because he hooked on woocommerce_breadcrumb.

You can override the Archive-product.php template in your topic.

 <?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 the functions.php function, you can also create such functions:

 function my_woocommerce_print_category_name() { //You can implements a function for get category name... } 
0
source

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

 <?php echo wc_get_product_category_list($product->get_id()) ?> 
0
source

Source: https://habr.com/ru/post/977731/


All Articles