将价格后的消息添加到多个类别

问题描述 投票:0回答:1

我有一个针对woocommerce的代码,在选择类别的产品价格之后增加“每平方英尺”。我添加了另一个类别,我想要“每平方英尺”也可以申请。我想我需要添加一个我尝试过但没有成功的数组。以下是我对单一类别有用的内容

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
 
function custom_price_message($price) {
 
if ( !has_term( 'stone', 'product_cat' ) ) {
   return $price;
    
} elseif (!empty($price)){
   $vat = ' per ft<sup>2</sup>';
   return $price . $vat;
    
 }else{
   return 'Call for Price';
 }
}
php wordpress woocommerce
1个回答
0
投票

不知道我第一次做错了什么但是在这里但我想通了。这是我使用的数组。

add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
 
function custom_price_message($price) {
    
// Set HERE your product categories in the array
$categories = array( 'stone', 'remnants' );
 
if( !has_term( $categories, 'product_cat' ) ){
   return $price;
    
} elseif (!empty($price)){
   $vat = ' per ft<sup>2</sup>';
   return $price . $vat;
    
 }else{
   return 'Call for Price';
 }
}
    
© www.soinside.com 2019 - 2024. All rights reserved.