用最低价格替换 WooCommerce 可变产品价格范围 [英] Replace WooCommerce variable products price range with the min price
问题描述
在我的 Woocommerce 网上商店中,我使用可变产品销售服务,并且我想将价格范围替换为起始价格"++ 最低价格.
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.
我曾尝试以多种方式更改代码,但没有成功.
I have tried changing the code in many ways but I didn't get it working.
如何在 Woocommerce 中隐藏价格范围并仅显示可变产品的最低价格?
How can I hide price range in Woocommerce and show only the lowest one on variable products?
推荐答案
以下将用最低价格的价格起始于"替换可变价格范围:
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 );
}
代码位于活动子主题(或活动主题)的 function.php 文件中.经测试有效.
Code goes in function.php file of your active child theme (or active theme). Tested and works.
相关:将 WooCommerce 可变产品价格范围替换为最高"和最高价格
这篇关于用最低价格替换 WooCommerce 可变产品价格范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!