简体   繁体   中英

Round up cart total Woocommerce

I need to round up prices on my Woocommerce cart. It rounds up to 1. For example:

If the total price of the cart is $40.85, I need the cart to show $41.00.

I tried with this command but the price discount this 0.15 and I do not know how to do it. I found this in other sites but round up the products in the catalog.

add_filter( 'woocommerce_calculated_total', 'custom_calculated_total', 10, 2 );
function custom_calculated_total( $total, $cart ){
    return round( $total - ($total * 0.15), $cart->dp );
}

Thanks for your help.

I believe this is what you're looking for. This will round your cart total to the next dollar. You can also use WooCommerce settings to round displayed product prices before items are added to the cart.

//round cart total up to nearest dollar
add_filter( 'woocommerce_calculated_total', 'custom_calculated_total' );
function custom_calculated_total( $total ) {
$total = round( $total, 1 );
return ceil($total);
}

I have tried Justin R.'s Code, with 50% success. The Total was rounded fine, but not the Subtotal. Here I found a Code that did both. It uses a different Hook "raw_woocommerce_price". This is the Code:

// Round price for .99 .01 decimals
add_filter( 'raw_woocommerce_price', function ( $price ) {
$decimals = round( $price - floor( $price ), 2 );
return ( $decimals == 0.01 || $decimals == 0.99 ) ? round( $price ) : $price;
} );

I am looks for some option how to round last digit in woocommerce cart and I cant find it. Maybe it will help somebody. This function works for me. Just add this code to your themes functions.php file and it will work.

//Rounding total price last digit in cart to zero:
add_filter( 'woocommerce_calculated_total', 'custom_calculated_total' );
function custom_calculated_total( $total ) {
$total = round($total / 10) * 10;
return ($total);
}

Thanks of the lovely snippet that works 100% fine.

How can I use this snippet for only ONE currency (INR) on a multicurrency setup?

I use different currencies on my website, but want to use ROUNDUP for INR only and leave other currencies with cents.

Is that possible?

Kindly help in this regard.

thanks in advance..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM