简体   繁体   中英

Get current term name in Woocommerce product category archive pages

I am trying to get single product category name of a product category archive page.

Using this code:

$categ = $product->get_categories(); 
echo $categ;

Its showing all parent category as well…

How to get the current term name in Woocommerce product category archive pages?

To get the product category term name of the current product category archive page, you will use:

// Only on product category archive pages
if(is_product_category()){
    // The WP_Term object for the current product category
    $term = get_queried_object();

    // Get the current term name for the product category page
    $term_name = $term->name;

    // Test output
    echo $term->name . '<br>';
}

Tested and works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM