在 WooCommerce 中应用优惠券后如何四舍五入价格?

问题描述 投票:0回答:1

我已将以下代码添加到我的function.php,但应用优惠券后它没有对价格进行四舍五入。

我正在使用 woocommerce 2.5.5。

这是我的代码:

add_filter( 'woocommerce_get_price_excluding_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_get_price_including_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_tax_round', 'round_price_product', 10, 1);
add_filter( 'woocommerce_get_price', 'round_price_product', 10, 1);

function round_price_product( $price ){
    // Return rounded price
    return round( $price );
}

出了什么问题?

php wordpress woocommerce product price
1个回答
3
投票

您正在函数中返回一个值,相反,也许您需要这样返回

$price
变量:

add_filter( 'woocommerce_get_price_excluding_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_get_price_including_tax', 'round_price_product', 10, 1 );
add_filter( 'woocommerce_tax_round', 'round_price_product', 10, 1);
add_filter( 'woocommerce_get_price', 'round_price_product', 10, 1);

function round_price_product( $price ){
    // Return rounded price
    return round($price);
}
© www.soinside.com 2019 - 2024. All rights reserved.