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_wrapper">SKU: <span class="sku">'. $product->get_sku() .'</span></span></BR><span class="material_wrapper">MATERIAL: <span class="material">'. $product->get_sku() .'</span></span>';
}
return $desc;
}
add_filter( 'woocommerce_short_description', 'herara_filter_short_description' );
product
) has a particular term in a taxonomy? ( where the taxonomy is the woocommerce product category taxonomy? ). How to test if a post has a term in a taxonomy is a much better question that achieves the same thing and is 100x easier to find an answer for.is_single
was false thennull
would be returned, overwriting any other filters, so I changed$new_desc
to$desc
. It's also not necessary to declare the$product
global and pass its ID, the current post is already set to that product so it already knows which post to checkproduct
, much like pages are posts of typepage
, products are just another custom post type. Much like categories and tags are taxonomies, so are product categories, under the hood they're all the same. ( note that if they were not, then this Q would be off topic, 3rd party plugin dev support is offtopic here so your question would have been closed )product_cat