Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将wordpress中的价格四舍五入到最接近的值?_Wordpress_Woocommerce - Fatal编程技术网

如何将wordpress中的价格四舍五入到最接近的值?

如何将wordpress中的价格四舍五入到最接近的值?,wordpress,woocommerce,Wordpress,Woocommerce,我正在使用以下函数在wordpress中汇总价格 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',

我正在使用以下函数在wordpress中汇总价格

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 ceil( $price );
}
上述函数将价格汇总为
如果价格为999.85卢比至1000卢比/-
如果价格为999.15卢比-至1000卢比/-

我想把价格汇总如下。
如果价格为999.55卢比至1000卢比/-
如果价格为999.15卢比-至999卢比/-


如何做到这一点…?

您只需使用php
round()
函数即可实现同样的效果,如下所示:

function round_price_product( $price ){
    // Return rounded price
    return round( $price );
}
希望对你有用