【发布时间】:2021-08-21 10:17:28
【问题描述】:
在使用此代码时,我可以操作小计(它工作正常)
add_action( 'woocommerce_calculate_totals', 'action_cart_calculate_totals', 10, 1 );
function action_cart_calculate_totals( $cart_object ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( !WC()->cart->is_empty() ):
## Displayed subtotal (+10%)
$cart_object->subtotal *= 1.1;
## Displayed TOTAL (+10%)
// $cart_object->total *= 1.1;
## Displayed TOTAL CART CONTENT (+10%)
// $cart_object->cart_contents_total *= 1.1;
endif;
}
但我想使用下面的代码,用于新的subtotal
add_filter( 'woocommerce_calculated_total', 'my_custom_roundoff' );
function my_custom_roundoff( $total ) {
$round_num = round($total / 0.05) * 0.05;
$total = number_format($round_num, 2); // this is required for showing zero in the last decimal
return $total;
}
但是这并没有达到预期的结果。如何在第一个提到的函数中使用这个舍入函数?
【问题讨论】:
标签: wordpress woocommerce cart hook-woocommerce subtotal