[英]Replace WooCommerce variable products price range with the min price
With my Woocommerce webshop, I sell services using variable products and I would like to replace the price range by "Prices starting at" ++ the lowest price.在我的 Woocommerce 网上商店中,我使用可变产品销售服务,并且我想将价格范围替换为“起始价格”++ 最低价格。
I have tried changing the code in many ways but I didn't get it working.我曾尝试以多种方式更改代码,但没有成功。
How can I hide price range in Woocommerce and show only the lowest one on variable products?如何在 Woocommerce 中隐藏价格范围并仅显示可变产品的最低价格范围?
The following will replace the variable price range by "Prices starting at" with the lowest price:以下将用最低价格的“价格起始于”替换可变价格范围:
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 );
}
Code goes in function.php file of your active child theme (or active theme).代码位于活动子主题(或活动主题)的 function.php 文件中。 Tested and works.
测试和工作。
Related: Replace WooCommerce variable products price range with 'Up to' and the max price相关: 将 WooCommerce 可变产品价格范围替换为“最高”和最高价格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.