How to round up the price in wordpress to the nearest value?

那年仲夏 提交于 2019-12-02 04:31:57

问题


I am using following function to round up the price in 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 );
}

The above function round up the prices like
If price Rs 999.85/- to Rs 1000/-
If price Rs 999.15/- to Rs 1000/-

I want round up the price like below..
If Price Rs 999.55/- to Rs 1000/-
If the price Rs 999.15/- to Rs 999/-

How to do this...?


回答1:


You can achieve the same by simply using the php round() function as like this :

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

Hope it works for you.



来源:https://stackoverflow.com/questions/29553670/how-to-round-up-the-price-in-wordpress-to-the-nearest-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!