douliao8760 2017-04-07 13:44
浏览 242
已采纳

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

Here is my WooCommerce website: sweetworldcandy.com

The issue is, in variable product price the least and the max value is showing what I want is if the product is not on sale show the least value if it is on sale show the least value and the least value of offer price by adding a slash as delete tag

I shared this three images below for reference:

enter image description here if not on saleenter image description here

  • 写回答

1条回答 默认 最新

  • doushang4293 2017-04-07 14:29
    关注

    The code below should do what you expect:

    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;
    }
    

    The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

    This code is tested and works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题