php - 汇总购物车总数 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);
}
推荐阅读
- javascript - 开玩笑在 DOM 链中测试属性更新
- java - jdk- 15.0.1_windows-x64_bin.exe 未打开
- mysql - 从MYSQL数据库中选择当前月份和下个月的所有数据
- html - 想自定义 UI,我们目前使用自定义策略和自定义 HTML 页面
- c# - Unity3d - 当场景中有多个 Collier 时,Raycast 不计算命中
- ios - 无法将 FirebaseAnalytics 或 Crashlytics cocoapod 添加到 kotlin 多平台共享模块
- node.js - 使用 laravel 微风运行 npm 时出现节点错误
- c# - 我的 MoveTowards 方法是在 Unity 中传送。我只希望它慢慢移动。我该怎么办?
- c# - 为什么我需要 Content/Type 变量?
- oracle - 根据版本减少数据