Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

wordpress

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


1 Answers

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.

like image 95
Haider Saeed Avatar answered Dec 04 '25 07:12

Haider Saeed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!