You may need to round the order amount in your WooCommerce Cart for many reasons. The most common example is the unwillingness to deal with pennies (cents). Especially taking into account the fact that many customers, when paying, independently round the amount in a direction convenient for them. After that, discrepancies are obtained between tax reporting (checks, income book) and the actual receipt of funds to the current account.

An order sum with a decimal part can occur for three reasons:

  • the prices of products are initially indicated with a decimal component;
  • the buyer has applied a coupon with an percent rate;
  • you have applied a percentage discount to the product(s).

Round the order amount using WooCommerce settings

Actually, you can round the total amount quite simply. On the first screen of the WooCommerce settings there is a setting “Number of decimals”.

Remove cents in order sum cart

Set this field to 0, and forget the decimals in the payment amounts.

Remove decimals with PHP code

But the previous method may not work for you if:

  • the bank or acquirer requires two decimal digits in the prices of products and the total amount payable;
  • you like to use prices 29.99 and 199.99 🙂

In this case, use the following code by adding it to the functions.php file in your active WordPress theme.

// Round Cart total by Speedplus.com.ua
add_filter( 'woocommerce_calculated_total', 'rounded_cart_total' );
function rounded_cart_total( $total ) {
$total = ceil($total);
return $total;
}

This PHP code uses the ceil() function, which rounds up the value (good for the seller). However, you can safely replace it with floor(), which will round the number down (good for clients). Well, or use round(), which works strictly according to the mathematical rules of rounding 😉

If you need custom rounding of the order amount or other help on the site, write to us in the Contacts section.

Leave a comment

Your email address will not be published.