Wordpress 如何添加';人均';在电子商务中的分类价格

Wordpress 如何添加';人均';在电子商务中的分类价格,wordpress,woocommerce,product,price,Wordpress,Woocommerce,Product,Price,使用woocommerce,我有几个类别,但想在“烹饪类”类别中添加“每人”。 我已经编写了这个函数,它适用于所有产品。 我似乎无法让它只在类别上工作 '/*---------Adds per person to price -------*/ add_filter( 'woocommerce_get_price_html', 'custom_price_html', 500, 2 ); function custom_price_html( $price, $product ) { if ((

使用woocommerce,我有几个类别,但想在“烹饪类”类别中添加“每人”。 我已经编写了这个函数,它适用于所有产品。 我似乎无法让它只在类别上工作

'/*---------Adds per person to price -------*/
add_filter( 'woocommerce_get_price_html', 'custom_price_html', 500, 2 );
function custom_price_html( $price, $product ) {
if (( int ) is_category( 'Cookery Classes','product_cat', $product->id ) )
$price .='per person';
$price .= '<span class="from"><BR>' . _x('per person', 'price_per_person','woocommerce') . ' </span>';
return $price;
}'
'/*-----------将人均成本增加到价格中-------*/
添加过滤器('woocommerce\u get\u price\u html','custom\u price\u html',500,2);
函数自定义\价格\ html($price,$product){
如果((int)是_类(‘烹饪类’、‘产品_类’、$product->id))
$price.='每人';
$price.='
'.'ux('perperperson'、'price'person'、'woocommerce'); 返回$price; }'
找到并安装了此插件:
https://wordpress.org/plugins/woocommerce-jetpack/

允许您为每个产品类别的价格添加自定义标签

我使用了一个名为自定义价格标签的插件来解决这个问题:尽管如此,仍然对解决方案感到好奇!