Это можно сделать, используя округление ловушки фильтра woocommerce_get_formatted_order_total Общая стоимость заказа непосредственно перед его форматированием для отображения в общей строке заказа:
add_filter( 'woocommerce_get_formatted_order_total', 'round_formatted_order_total', 10, 2 );
function round_formatted_order_total( $formatted_total, $order ) {
$formatted_total = wc_price( round( $order->get_total() ), array( 'currency' => $order->get_currency() ) );
return $formatted_total;
}
Код помещается в файл function.php вашей активной дочерней темы (или активнойтема).Протестировано и работает.
Или, если вам нужно округлить все суммы ордеров, вместо этого вы будете использовать хук woocommerce_get_order_item_totals
, где вам придется округлять все нужные вам строки.
В приведенном ниже примере итоговые и итоговые строки будут округлены:
add_filter( 'woocommerce_get_order_item_totals', 'rounded_formatted_order_totals', 10, 3 );
function rounded_formatted_order_totals( $total_rows, $order, $tax_display ) {
$tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
// For subtotal line
if ( isset( $total_rows['cart_subtotal'] ) ) {
$subtotal = 0;
foreach ( $order->get_items() as $item ) {
$subtotal += $item->get_subtotal();
if ( 'incl' === $tax_display ) {
$subtotal += $item->get_subtotal_tax();
}
}
$subtotal = wc_price( round( $subtotal ), array( 'currency' => $order->get_currency() ) );
if ( 'excl' === $tax_display && $this->get_prices_include_tax() ) {
$subtotal .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
}
$total_rows['cart_subtotal']['value'] = $subtotal;
}
// For total line
if ( isset( $total_rows['order_total'] ) ) {
$total = wc_price( round( $order->get_total() ), array( 'currency' => $order->get_currency() ) );
$total_rows['order_total']['value'] = $total;
}
return $total_rows;
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы).Проверено и работает.