Php 综合购物车

Php 综合购物车,php,wordpress,woocommerce,cart,Php,Wordpress,Woocommerce,Cart,我需要在我的购物车上汇总价格。它取整为1。例如: 如果购物车的总价格是$40.85,我需要购物车显示$41.00 我尝试使用此命令,但价格折扣为0.15,我不知道如何操作。我在其他网站上发现了这个,但在目录中对产品进行了汇总 add_filter( 'woocommerce_calculated_total', 'custom_calculated_total', 10, 2 ); function custom_calculated_total( $total, $cart ){ re

我需要在我的购物车上汇总价格。它取整为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);
}

我相信这就是你要找的。这将使您的购物车总额达到下一美元。在将商品添加到购物车之前,您还可以使用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%。总数四舍五入,但不是小计。我找到了一个既能做这两件事的代码。它使用了一个不同的钩子“原始价格”。 代码如下:

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

我试过Justin R.的代码,成功率为50%。总数四舍五入,但不是小计。我找到了一个既能做这两件事的代码。它使用了一个不同的钩子“原始价格”。 代码如下:

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

没问题。很高兴这有帮助。:)没问题。很高兴这有帮助。:)