How to test If a post has a particular term

I want to display a different description for a post if it belongs to a specific product category in a filter.

I've used the code below code to add the code but it is displaying for all products:

function herara_filter_short_description( $desc ){
    global $product;
    if ( is_single( $product-id ) ) {
        $desc = 'span class=sku_wrapperSKU: span class=sku'. $product-get_sku() .'/span/span/BRspan class=material_wrapperMATERIAL: span class=material'. $product-get_sku() .'/span/span';
    }
    return $desc;
}
add_filter( 'woocommerce_short_description', 'herara_filter_short_description' );

Topic description shortcode Wordpress

Category Web


You can test if a post has a particular term assigned to it with the has_term function.

E.g.

if ( has_term( 'term-slug', 'taxonomy-slug' ) ) {
    // do stuff
}

With this you can test if your "post" has a particular "term" ( aka if your "product" has a particular "product_cat" )

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.