Skip to content
Advertisement

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.

Advertisement

Answer

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);
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement