我想在适用于我的大多数产品的描述之后在我的所有产品上显示一条消息。但是,问题在于,在可变产品上,该消息将同时显示在产品的整体描述和选择变体时。
因此,我不希望选择变体时其他文本,因此我修改了我的功能以添加其他if语句。现在的功能如下:
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;
}
}
但是,这仍然不起作用,并且文本出现在两个地方。我也尝试将产品类型更改为变量,但随后消息都没有出现在任何地方。
有没有办法让我在产品是变体时不会添加消息?