You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WooCommerce 3.09:可变产品常规价格范围未显示问题咨询

解决WooCommerce 3.0.9可变产品常规价格范围不显示的问题

我之前帮不少开发者处理过WooCommerce这个版本的价格显示问题,你遇到的可变产品只显示促销价范围、缺失常规价格(带删除线)的情况,在3.0.x版本里确实是个常见的小bug,下面给你几个靠谱的解决办法:

方法一:通过主题functions.php添加修复代码

这个方法直接针对WooCommerce的价格模板逻辑做补全,把缺失的常规价格范围输出补上。你可以把下面的代码添加到当前主题的functions.php文件末尾(注意先备份文件,避免操作出错):

add_filter( 'woocommerce_variable_sale_price_html', 'wc_variable_product_display_regular_price_range', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_variable_product_display_regular_price_range', 10, 2 );

function wc_variable_product_display_regular_price_range( $price, $product ) {
    // 只处理可变产品且处于促销状态的情况
    if ( $product->is_type('variable') && $product->is_on_sale() ) {
        $regular_price_min = $product->get_variation_regular_price( 'min', true );
        $regular_price_max = $product->get_variation_regular_price( 'max', true );
        $sale_price_min = $product->get_variation_sale_price( 'min', true );
        $sale_price_max = $product->get_variation_sale_price( 'max', true );

        // 处理价格范围首尾一致的情况(即所有变体价格相同)
        if ( $regular_price_min === $regular_price_max ) {
            $regular_price = wc_price( $regular_price_min );
        } else {
            $regular_price = wc_format_price_range( $regular_price_min, $regular_price_max );
        }

        if ( $sale_price_min === $sale_price_max ) {
            $sale_price = wc_price( $sale_price_min );
        } else {
            $sale_price = wc_format_price_range( $sale_price_min, $sale_price_max );
        }

        // 组合成和简单产品一致的显示格式:删除线常规价 + 高亮促销价
        $price = '<del>' . $regular_price . '</del> <ins>' . $sale_price . '</ins>';
    }
    return $price;
}

这段代码会强制WooCommerce输出可变产品的常规价格范围,保持和简单产品相同的价格展示逻辑。

方法二:检查主题兼容性与后台设置

  • 先确认你的主题是否自定义了WooCommerce价格模板(比如single-product/price.php或single-product/add-to-cart/variable.php文件)。如果主题有自己的模板,可能是模板代码里缺失了常规价格范围的输出逻辑,你可以对比WooCommerce官方默认模板的代码,把缺失的部分补进去。
  • 进入WooCommerce后台的设置 > 产品 > 显示,确认“价格格式”选项是否设置为“显示常规价格和促销价格”(这个选项在3.0.9版本中是存在的)。

方法三:升级WooCommerce版本(可选)

WooCommerce 3.0.9是比较老旧的版本,后续的更新已经修复了不少这类显示类bug。如果你的主题和插件都兼容更高版本的WooCommerce,建议升级到3.x系列的最新子版本,或者更高的稳定大版本,这样既能从根源解决问题,还能获得更多安全更新和功能优化。


内容的提问来源于stack exchange,提问作者Netzlounge

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:00:59