[英]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? 如何在Woocommerce产品类别归档页面中获得当前术语名称?
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. 经过测试和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.