【问题标题】:Exclude category from single product description( woocommerce) and make it not linkable从单个产品描述(woocommerce)中排除类别并使其不可链接
【发布时间】:2015-08-20 07:02:22
【问题描述】:

我有 woocommerce 的 wordpress 主题。每个产品都有描述类别,如类别:新品、书籍。我想排除一个类别(新)并使其不可点击(删除 hrev) 我找到了这个标签的行,但不知道如何正确编辑。有任何想法吗?谢谢!

<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '.</span>' ); ?>

woocommerce plugin

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    替换这一行:

    <?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '.</span>' ); ?>
    

    用这个:

    $terms = get_the_terms( $post->ID, 'product_cat' );
    echo '<span class="posted_in">';
        foreach ( $terms as $term ) {
            $term_link = get_term_link( $term );
            if( $term->name == 'New' ){
                echo ' ' . $term->name;
            }else{
                echo ' <a href="' . esc_url( $term_link ) . '">' . $term->name . '</a>';
            }
        }
    echo '</span>';
    

    您可以根据自己的要求对其进行自定义。可能这会有所帮助。

    【讨论】:

    • 它有效!但是如果可能的话,我想解决一些问题。我很乐意从此列表中删除类别“新”并添加简单的文本,例如 (PRODUCT TYPE :),谢谢
    • if( $term->name == 'New' ){ // 什么都不做 }else{ 这是删除猫的正确代码,woocoomerce 作者给了我。谢谢海德尔!!
    • 欢迎兄弟,感谢 Stackoverflow 社区。 :)
    猜你喜欢
    • 2021-12-11
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-17
    • 2019-08-05
    • 1970-01-01
    • 2018-11-09
    相关资源
    最近更新 更多