繁体   English   中英

在Woocommerce产品类别存档页面中获取当前术语名称

[英]Get current term name in Woocommerce product category archive pages

我正在尝试获取产品类别存档页面的单个产品类别名称。

使用此代码:

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

它也显示所有父类别...

如何在Woocommerce产品类别归档页面中获得当前术语名称?

要获取当前产品类别归档页面的产品类别术语名称,您将使用:

// 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>';
}

经过测试和工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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