我在用"更改 Woocommerce 购物车总数中的小数位数 https://stackoverflow.com/questions/49550127/change-number-of-decimals-in-woocommerce-cart-totals/49551246#49551246"显示总数的答案代码2 位小数。该代码适用于购物车和结帐页面中显示的总数。
如果可能的话,我也想对小计做同样的事情。任何帮助表示赞赏。
要在购物车和结帐页面中将显示的小计金额格式化为 2 位小数,请使用以下命令:
// Displayed formatted cart subtotal in cart and checkout pages
add_filter( 'woocommerce_cart_subtotal', 'filter_cart_subtotal_html', 10, 3 );
function filter_cart_subtotal_html( $cart_subtotal, $compound, $cart ) {
$decimals = 2; // <== <== Set the number of decimals to be displayed
$args = ['decimals' => strval($decimals)]; // Initializing
if ( $compound ) {
$cart_subtotal = wc_price( $cart->get_cart_contents_total() + $cart->get_shipping_total() + $cart->get_taxes_total( false, false ), $args );
} elseif ( $cart->display_prices_including_tax() ) {
$cart_subtotal = wc_price( $cart->get_subtotal() + $cart->get_subtotal_tax(), $args );
if ( $cart->get_subtotal_tax() > 0 && ! wc_prices_include_tax() ) {
$cart_subtotal .= ' <small class="tax_label">' . WC()->countries->inc_tax_or_vat() . '</small>';
}
} else {
$cart_subtotal = wc_price( $cart->get_subtotal(), $args );
if ( $cart->get_subtotal_tax() > 0 && wc_prices_include_tax() ) {
$cart_subtotal .= ' <small class="tax_label">' . WC()->countries->ex_tax_or_vat() . '</small>';
}
}
return $cart_subtotal;
}
代码位于活动子主题(或活动主题)的functions.php 文件或插件文件中。经过测试并有效。
有关的:更改 Woocommerce 购物车总数中的小数位数 https://stackoverflow.com/questions/49550127/change-number-of-decimals-in-woocommerce-cart-totals/49551246#49551246
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)