我已将以下代码添加到我的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 );
}
出了什么问题?
您正在函数中返回一个值,相反,也许您需要这样返回
$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);
}