汇总购物车总数 Woocommerce

Round up cart total Woocommerce

我需要在我的 Woocommerce 购物车上汇总价格。它四舍五入为 1。例如:

如果购物车的总价是 40.85 美元,我需要购物车显示 41.00 美元。

我试过这个命令,但价格优惠了 0.15,我不知道该怎么做。我在其他网站上找到了这个,但将目录中的产品汇总起来。

add_filter( 'woocommerce_calculated_total', 'custom_calculated_total', 10, 2 );
function custom_calculated_total( $total, $cart ){
    return round( $total - ($total * 0.15), $cart->dp );
}

感谢您的帮助。

我相信这就是您要找的。这会将您的购物车总额四舍五入到下一美元。您还可以使用 WooCommerce 设置在将商品添加到购物车之前四舍五入显示的商品价格。

//round cart total up to nearest dollar
add_filter( 'woocommerce_calculated_total', 'custom_calculated_total' );
function custom_calculated_total( $total ) {
$total = round( $total, 1 );
return ceil($total);
}

我试过 Justin R. 的代码,成功率为 50%。总计四舍五入,但不是小计。 Here 我找到了一个代码可以做到这两个。它使用不同的 Hook“raw_woocommerce_price”。 这是代码:

// Round price for .99 .01 decimals
add_filter( 'raw_woocommerce_price', function ( $price ) {
$decimals = round( $price - floor( $price ), 2 );
return ( $decimals == 0.01 || $decimals == 0.99 ) ? round( $price ) : $price;
} );

我正在寻找一些选项如何舍入 woocommerce 购物车中的最后一位数字,但我找不到。也许它会帮助某人。这个功能对我有用。只需将此代码添加到您的主题 functions.php 文件中即可。

//Rounding total price last digit in cart to zero:
add_filter( 'woocommerce_calculated_total', 'custom_calculated_total' );
function custom_calculated_total( $total ) {
$total = round($total / 10) * 10;
return ($total);
}