首页 > 解决方案 > 汇总购物车总数 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 );
}

谢谢你的帮助。

标签: phpwordpresswoocommercecart

解决方案


我相信这就是你要找的。这会将您的购物车总数四舍五入到下一美元。您还可以在将商品添加到购物车之前使用 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);
}

推荐阅读