How to round up the price in wordpress to the near

2019-02-25 16:50发布

问题:

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.