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

Add a custom label to the max price for Woocommerce variable products

在 WooCommerce 中,我需要像本网站那样显示所有变体价格 koenigvineyards.com, 最低价格和 "Wine club price" (最高价格).

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

要将自定义文本标签添加到可变产品的最高价格(如 "Wine club price"),您可以使用挂接到 woocommerce_format_price_range 中的此函数以这种方式过滤挂钩:

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;
}

代码进入您的活动子主题(或活动主题)的 function.php 文件或任何插件文件。

已测试并有效。