user3852799
user3852799

Reputation:

Exclude category from single product description( woocommerce) and make it not linkable

I have wordpress theme with woocommerce. Every single product have in description category like categories : new, books. I want to exclude one category(new) and make it not clickable(remove a hrev) I found line of this tag but dont know how to edit right. Any ideas? THANKS!

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

woocommerce plugin

Upvotes: 3

Views: 1732

Answers (1)

Haider Saeed
Haider Saeed

Reputation: 287

replace this line:

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

with this:

$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>';

You can customize it according to your requirements. May be this will help.

Upvotes: 2

Related Questions