我建立了一个woocommerce商店以进行测试,并试图将总价格四舍五入为0.05,因为我们在瑞士这样做;)
但是我没有成功,到处搜寻。
此刻我的代码如下:
add_filter( 'woocommerce_calculated_total', 'round_price_product', 10, 1);
add_filter( 'woocommerce_calculated_subtotal', 'round_price_product', 10, 1);
add_filter( 'woocommerce_cart_subtotal', 'round_subtotal', 10, 3);
function round_subtotal( $cart_subtotal, $compound, $instance ) {
$origValue = $cart_subtotal;
preg_match( '/\d+\.\d+/', $origValue, $floatValue);
$roundedValue = number_format( round_price_product( $floatValue[0] ), 2 );
$returnValue = str_replace( $floatValue, $roundedValue, $origValue );
return $returnValue;
}
function round_price_product( $price ){
return round( $price * 2, 1 ) / 2;
}
有什么建议吗?
谢谢, 克里斯