【问题标题】:Get current term name in Woocommerce product category archive pages在 Woocommerce 产品类别存档页面中获取当前术语名称
【发布时间】:2018-12-09 10:43:39
【问题描述】:

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

使用此代码:

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

它也显示了所有的父类别……

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

【问题讨论】:

    标签: php wordpress woocommerce custom-taxonomy


    【解决方案1】:

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

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

    经过测试并且有效。

    【讨论】:

    • 感谢您的回复,但如果我还需要在商店页面中显示最后一个子类别怎么办。感谢您的回复
    • @DevalMungalpara 您的问题似乎不清楚、不详细且不完整。我们不知道您在哪里以及如何使用该代码,而且您似乎也在使用 ACF 自定义字段,这在您的问题中没有提到。我们对使用的版本一无所知...
    猜你喜欢
    • 2021-06-18
    • 2018-12-10
    • 1970-01-01
    • 2016-02-23
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 2020-11-02
    相关资源
    最近更新 更多