Woocommerce在折扣上只显示可变产品的一个价格

Sha*_*aik 3 php wordpress product woocommerce hook-woocommerce

这是我的WooCommerce网站:sweetworldcandy.com

问题是,在可变产品价格中,最小值和最大值显示我想要的是,如果产品没有出售,则显示出价值最低的值,如果出售,则显示最低价值和最低价格的报价斜杠作为删除标记

我在下面分享了这三张图片以供参考:

在此输入图像描述 如果没有发售在此输入图像描述

Loi*_*tec 8

下面的代码应该符合您的期望:

add_filter('woocommerce_variable_sale_price_html', 'shop_variable_product_price', 10, 2);
add_filter('woocommerce_variable_price_html','shop_variable_product_price', 10, 2 );
function shop_variable_product_price( $price, $product ){
    $variation_min_reg_price = $product->get_variation_regular_price('min', true);
    $variation_min_sale_price = $product->get_variation_sale_price('min', true);
    if ( $product->is_on_sale() && !empty($variation_min_sale_price)){
        if ( !empty($variation_min_sale_price) )
            $price = '<del class="strike">' .  woocommerce_price($variation_min_reg_price) . '</del>
        <ins class="highlight">' .  woocommerce_price($variation_min_sale_price) . '</ins>';
    } else {
        if(!empty($variation_min_reg_price))
            $price = '<ins class="highlight">'.woocommerce_price( $variation_min_reg_price ).'</ins>';
        else
            $price = '<ins class="highlight">'.woocommerce_price( $product->regular_price ).'</ins>';
    }
    return $price;
}
Run Code Online (Sandbox Code Playgroud)

代码放在活动子主题(或主题)的function.php文件中,或者放在任何插件文件中.

此代码经过测试和运行.