Php 为可变产品的最高价格添加自定义标签

Php 为可变产品的最高价格添加自定义标签,php,wordpress,woocommerce,product,price,Php,Wordpress,Woocommerce,Product,Price,在WooCommerce中,我需要显示所有与此站点类似的变化价格, 最低价格和“葡萄酒俱乐部价格”(最高价格) 如何在WooCommerce中可变产品的最高价格之前添加自定义标签?要将自定义文本标签添加到可变产品的最高价格(如“葡萄酒俱乐部价格”),您可以通过以下方式使用链接在WooCommerce格式价格范围中的此函数: add_filter( 'woocommerce_format_price_range', 'custom_format_price_range', 10, 3 ); fun

在WooCommerce中,我需要显示所有与此站点类似的变化价格, 最低价格和“葡萄酒俱乐部价格”(最高价格)


如何在WooCommerce中可变产品的最高价格之前添加自定义标签?

要将自定义文本标签添加到可变产品的最高价格(如“葡萄酒俱乐部价格”),您可以通过以下方式使用链接在WooCommerce格式价格范围中的此函数:

add_filter( 'woocommerce_format_price_range', 'custom_format_price_range', 10, 3 );
function custom_format_price_range( $price, $from, $to ) {
    $text_max = '<span class"wine-club-label">'.__( "Wine club price" ).': </span>';
    $price = sprintf( _x( '%1$s &ndash; %2$s', 'Price range: from-to', 'woocommerce' ), is_numeric( $from ) ? wc_price( $from ) : $from, is_numeric( $to ) ? $text_max . wc_price( $to ) : $text_max . $to );
    return $price;
}
add_filter('woocommerce_format_price_range','custom_format_price_range',10,3);
函数自定义\格式\价格\范围($price,$from,$to){
$text_max=''.''(“葡萄酒俱乐部价格”):';
$price=sprintf(x(“%1$s&ndash;%2$s”,“价格范围:从到”,“woocommerce”),是数字($from)?wc_price($from):$from,是数字($to)?$text_max.wc_price($to):$text_max.$to);
返回$price;
}
代码位于活动子主题(或活动主题)的function.php文件或任何插件文件中

测试和工作