【问题标题】:Hide particular tag from product page in Woocommerce在 Woocommerce 的产品页面中隐藏特定标签
【发布时间】:2022-01-12 10:55:15
【问题描述】:

有人知道如何从 WooCommerce 产品页面的标​​签列表中隐藏一个特定的标签名称吗?

示例:在产品页面中,我看到标签:1、2、3。我不想在标签 2 出现的每个产品页面的标​​签列表中显示标签 2。只有 1 和 3。

感谢您的帮助。

【问题讨论】:

  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: css woocommerce tags product


【解决方案1】:

您可以使用get_the_terms 过滤器挂钩。试试下面的代码。代码将进入您的活动主题 functions.php 文件。

function remove_tags_links( $terms, $post_id, $taxonomy ){

    if( is_admin() ) return;

    // onlu apply for product_tag.
    if( $taxonomy == 'product_tag' ){

        $slugs_to_hide = array( 'test-2' ); // degine slug of tags you want to hide.
        $new_terms     = array(); // store only showing terms

        if( !empty( $terms ) ){
            foreach ( $terms as $key => $term ) {
                if( !in_array( $term->slug, $slugs_to_hide ) ){
                    $new_terms[$key] = $term;
                }
            }
        }

        return $new_terms;
    }

    return $terms;

}
add_filter( 'get_the_terms', 'remove_tags_links', 10, 3 );

经过测试且有效

【讨论】:

  • 这是我一直在寻找的解决方案。非常感谢。
  • 欢迎...很高兴为您提供帮助。如果这个答案对你有帮助,那么你可以accept 答案,如果你喜欢/想要你也可以upvote 答案,谢谢。
猜你喜欢
  • 2018-04-23
  • 2015-10-07
  • 2018-07-18
  • 2019-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-26
相关资源
最近更新 更多