wordpress - Woocommerce 过滤器自定义(四舍五入与下限)

标签 wordpress filter woocommerce rounding floor

我在 Woocommerce 源代码中有这个过滤器:

$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', round( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total + $this->fee_total, $this->dp ), $this ) );

我想通过我的过滤器应用此更改,但我不明白如何操作。

$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', floor(( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total + $this->fee_total) * 100)/100, $this ) ); 

任何帮助将不胜感激。问候!

最佳答案

完成!

function custom_round_function( $total, $cart ) {

$total = floor(($cart->cart_contents_total + $cart->tax_total + $cart->shipping_tax_total + $cart->shipping_total + $cart->fee_total) * 100)/100;

return $total;
}

add_filter( 'woocommerce_calculated_total', 'custom_round_function', 10, 2 );

关于wordpress - Woocommerce 过滤器自定义(四舍五入与下限),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37729605/

相关文章:

php - 如果使用 MySQL IN 语句从数组中找不到匹配项,则返回 0

php - 打印页面 onclick 上函数的结果?

javascript - Woocommerce:未触发交付方法更改事件处理程序

css - 如何设置小部件位置的CSS

html - Wordpress 使用自定义 CSS 删除 CSS 内容

Scala 过滤器扩展

php - 在 Woocommerce 商店页面上获取产品变体图像

php - 产品图片设置不保存 woocommerce

php - 将 wc_get_product() 与用于产品 ID 的 PHP 变量一起使用

javascript - 当属性不相同时过滤数组属性的值