【问题标题】:How to round price after applying coupon in WooCommerce?在 WooCommerce 中应用优惠券后如何舍入价格?
【发布时间】:2016-06-10 12:04:58
【问题描述】:

我已将以下代码添加到我的 function.php 中,但在应用优惠券后它没有对价格进行四舍五入。

我正在使用 woocommerce 2.5.5。

这是我的代码:

add_filter( 'woocommerce_get_price_excluding_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_get_price_including_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_tax_round', 'round_price_product', 10, 1);
add_filter( 'woocommerce_get_price', 'round_price_product', 10, 1);

function round_price_product( $price ){
    // Return rounded price
    return round( $price );
}

怎么了?

【问题讨论】:

    标签: php wordpress woocommerce product price


    【解决方案1】:

    您在函数中返回一个值,相反,您可能需要以这种方式返回 $price 变量:

    add_filter( 'woocommerce_get_price_excluding_tax', 'round_price_product', 10, 1 );
    add_filter( 'woocommerce_get_price_including_tax', 'round_price_product', 10, 1 );
    add_filter( 'woocommerce_tax_round', 'round_price_product', 10, 1);
    add_filter( 'woocommerce_get_price', 'round_price_product', 10, 1);
    
    function round_price_product( $price ){
      //Store and Return rounded price
      $price = round( $price );
      return $price;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 2017-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多