Round Percentage Coupon Discounts in WooCommerce

Quick Summary

  • Filter woocommerce_coupon_get_discount_amount and run ceil on the discount, so percentage coupons give whole-number discounts instead of cents.
  • Fixed cart coupons are skipped and others rounded up; swap in round for the nearest whole number or floor to always round down.
  • Each cart item's discount is rounded separately, so the total can end up slightly higher than rounding the order's discount once.

A percentage coupon in WooCommerce often produces a discount with cents, such as 12.35 off. If you would rather give whole-number discounts, this filter rounds the coupon discount up to the next whole unit of your currency.

Add it to your child theme’s functions.php file.

PHP
add_filter( 'woocommerce_coupon_get_discount_amount', 'filter_woocommerce_coupon_get_discount_amount', 10, 5 );
function filter_woocommerce_coupon_get_discount_amount( $discount, $discounting_amount, $cart_item, $single, $instance ) {
    // Round the discount for all other coupon types than 'fixed_cart'
    if( ! $instance->is_type('fixed_cart') )
        $discount = ceil( $discount );

    return $discount; 
}

How it works

  • woocommerce_coupon_get_discount_amount lets you change the discount WooCommerce calculated for a coupon. It passes five values; the last one, $instance, is the coupon object.
  • is_type('fixed_cart') skips fixed cart coupons, whose amount is split across the cart items. Percentage and fixed product coupons are rounded.
  • ceil() always rounds up, so 12.10 becomes 13 and the customer gets slightly more off. Use round() for the nearest whole number or floor() to always round down.
  • The filter receives one cart item at a time ($cart_item), so each item’s discount is rounded separately. With several items in the cart, the total discount can end up a little higher than rounding the order’s discount once.

Test a few carts with different products and quantities before you go live, and clear any page cache afterwards.

Coupon and pricing rules that go beyond the defaults are part of the custom WooCommerce work I take on.

Share on X (opens in a new tab) Share on LinkedIn (opens in a new tab) Share on Facebook (opens in a new tab)

ChatGPT (opens in a new tab) Claude (opens in a new tab) Gemini (opens in a new tab) Perplexity (opens in a new tab) Grok (opens in a new tab)

More Insights

See More