用最低价格替换WooCommerce可变产品价格范围

时间:2019-02-14 20:17:47

标签: php wordpress woocommerce product price

在我的Woocommerce网上商店中,我使用可变产品来销售服务,我希望将价格范围替换为“最低价格开始” ++。

我尝试过多种方式来更改代码,但是我没有使它起作用。

如何在Woocommerce中隐藏价格范围并仅显示可变产品中的最低价格?

1 个答案:

答案 0 :(得分:0)

以下将用最低价格的“价格始于”替换可变价格范围:

add_filter( 'woocommerce_variable_sale_price_html', 'custom_variable_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'custom_variable_price_range', 10, 2 );
function custom_variable_price_range( $price_html, $product ) {

    $prefix     = __('Prices starting at', 'woocommerce');
    $min_price  = $product->get_variation_price( 'min', true );

    return $prefix . ' ' . wc_price( $min_price );
}

代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试,可以正常工作。

相关:Replace WooCommerce variable products price range with 'Up to' and the max price

相关问题