I want to show a message on all my products after the description which works on most of my products. However, the problem is that on variable products, the message would show both on the overall description of the product AND when a variant was selected.
So I don't want the additional text when the variant is chosen so I amended my function to add an else if statement. The function is now as follows:
add_filter('woocommerce_short_description','ts_add_text_short_descr');
function ts_add_text_short_descr($description){
global $post;
global $product;
// Don't want the message if the product is in these specific categories
if ( has_term( "training-courses-v2", "product_cat", $post->ID ) || has_term( "online-training-courses", "product_cat", $post->ID ) ) {
return $description;
}
else if ( $product->is_type( 'variation' ) ) {
return $description;
}
else {
$text="<strong>Please note that as this is a hygiene product, only unopened products in their original, unopened condition and in their original packaging are eligible for a refund.</strong>";
return $description.$text;
}
}
However, this still doesn't work and the text appears in both places. I tried also changing the product type to be variable but then the message doesn't appear in either place.
Is there a way I can get it so the message doesn't get added when the product is a variation?