我需要在 WooCommerce 购物车上为 woocommerce 产品的价格添加后缀文本。
基于 How to add suffix text to price in WooCommerce cart and checkout page? 的答案,所以我正在尝试修改该代码以识别产品类别。
我也在使用来自 this answer 的 String getNewDateTime(DateTime date) {
final String y = date.year.toString();
final String m = date.month.toString();
final String d = date.day.toString();
final String h = date.hour.toString();
final String min = date.minute.toString();
final String sec = date.second.toString();
return "$y-$m-${d}T$h:$min:$sec";
}
自定义条件函数。
这是我的代码:
has_product_categories()
遗憾的是,我不断收到以下错误:
add_filter( 'woocommerce_cart_item_price', 'kd_custom_price_message' );
add_filter( 'woocommerce_cart_item_subtotal', 'kd_custom_price_message' );
add_filter( 'woocommerce_cart_subtotal', 'kd_custom_price_message' );
add_filter( 'woocommerce_cart_total', 'kd_custom_price_message' );
function kd_custom_price_message( $price ) {
if( is_cart() && has_product_categories( '46' ) ){
$afterPriceSymbol = ' Monthly';
return $price . $afterPriceSymbol;
} else {
return $price;
}
}
我既无法将两者结合起来(例如在此处包含后缀一),也无法将其调整为后缀文本一。
知道我遗漏了什么吗?