diff --git a/includes/abstracts/abstract-wc-order.php b/includes/abstracts/abstract-wc-order.php index f723dad4800..00c2abd5718 100644 --- a/includes/abstracts/abstract-wc-order.php +++ b/includes/abstracts/abstract-wc-order.php @@ -1484,7 +1484,7 @@ abstract class WC_Abstract_Order { $total_discount = (double) $this->cart_discount + (double) $this->cart_discount_tax; } } - return apply_filters( 'woocommerce_order_amount_total_discount', round( $total_discount, WC_ROUNDING_PRECISION ), $this ); + return apply_filters( 'woocommerce_order_amount_total_discount', round( $total_discount, wc_get_rounding_precision() ), $this ); } /** diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php index b248c6fe3b4..60b60c99e9a 100644 --- a/includes/admin/class-wc-admin-assets.php +++ b/includes/admin/class-wc-admin-assets.php @@ -277,7 +277,7 @@ class WC_Admin_Assets { 'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ), 'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ), 'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS - 'rounding_precision' => WC_ROUNDING_PRECISION, + 'rounding_precision' => wc_get_rounding_precision(), 'tax_rounding_mode' => WC_TAX_ROUNDING_MODE, 'product_types' => array_unique( array_merge( array( 'simple', 'grouped', 'variable', 'external' ), array_keys( wc_get_product_types() ) ) ), 'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ), diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php index 5563396eb9f..38efb49622b 100644 --- a/includes/class-wc-cart.php +++ b/includes/class-wc-cart.php @@ -1260,7 +1260,7 @@ class WC_Cart { $line_subtotal_tax = 0; $line_subtotal = $line_price; $line_tax = 0; - $line_total = round( $discounted_price * $values['quantity'], WC_ROUNDING_PRECISION ); + $line_total = round( $discounted_price * $values['quantity'], wc_get_rounding_precision() ); /** * Prices include tax. @@ -1283,7 +1283,7 @@ class WC_Cart { $taxes = WC_Tax::calc_tax( $line_price, $base_tax_rates, true, true ); // Now we have a new item price (excluding TAX) - $line_subtotal = round( $line_price - array_sum( $taxes ), WC_ROUNDING_PRECISION ); + $line_subtotal = round( $line_price - array_sum( $taxes ), wc_get_rounding_precision() ); $taxes = WC_Tax::calc_tax( $line_subtotal, $item_tax_rates ); $line_subtotal_tax = array_sum( $taxes ); diff --git a/includes/class-wc-coupon.php b/includes/class-wc-coupon.php index 341a86f73ca..b830811b074 100644 --- a/includes/class-wc-coupon.php +++ b/includes/class-wc-coupon.php @@ -737,7 +737,7 @@ class WC_Coupon { } } - $discount = wc_cart_round_discount( $discount, WC_ROUNDING_PRECISION ); + $discount = wc_cart_round_discount( $discount, wc_get_rounding_precision() ); return apply_filters( 'woocommerce_coupon_get_discount_amount', $discount, $discounting_amount, $cart_item, $single, $this ); } diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php index 83c68ee9bda..16f8d39d433 100644 --- a/includes/class-wc-tax.php +++ b/includes/class-wc-tax.php @@ -35,7 +35,7 @@ class WC_Tax { * @access public */ public static function init() { - self::$precision = WC_ROUNDING_PRECISION; + self::$precision = wc_get_rounding_precision(); self::$round_at_subtotal = 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' ); } diff --git a/includes/wc-core-functions.php b/includes/wc-core-functions.php index 66a18190131..89ef6103158 100644 --- a/includes/wc-core-functions.php +++ b/includes/wc-core-functions.php @@ -1353,3 +1353,17 @@ function wc_product_attribute_uasort_comparison( $a, $b ) { } return ( $a['position'] < $b['position'] ) ? -1 : 1; } + +/** + * Get rounding precision. + * + * @since 2.6.3 + * @return int + */ +function wc_get_rounding_precision() { + if ( defined( 'WC_ROUNDING_PRECISION' ) ) { + return absint( WC_ROUNDING_PRECISION ); + } + + return wc_get_price_decimals() + 2; +} diff --git a/tests/unit-tests/util/main-class.php b/tests/unit-tests/util/main-class.php index e525c9b9ad4..b3d969aac4d 100644 --- a/tests/unit-tests/util/main-class.php +++ b/tests/unit-tests/util/main-class.php @@ -46,7 +46,6 @@ class WC_Tests_Main_Class extends WC_Unit_Test_Case { $this->assertEquals( $this->wc->version, WC_VERSION ); $this->assertEquals( WC_VERSION, WOOCOMMERCE_VERSION ); - $this->assertEquals( 4, WC_ROUNDING_PRECISION ); $this->assertContains( WC_TAX_ROUNDING_MODE, array( 2, 1 ) ); $this->assertEquals( '|', WC_DELIMITER ); $this->assertNotEquals( WC_LOG_DIR, '' ); diff --git a/woocommerce.php b/woocommerce.php index e26f4706b4f..8fd54d966a3 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -181,7 +181,6 @@ final class WooCommerce { $this->define( 'WC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) ); $this->define( 'WC_VERSION', $this->version ); $this->define( 'WOOCOMMERCE_VERSION', $this->version ); - $this->define( 'WC_ROUNDING_PRECISION', 4 ); $this->define( 'WC_DISCOUNT_ROUNDING_MODE', 2 ); $this->define( 'WC_TAX_ROUNDING_MODE', 'yes' === get_option( 'woocommerce_prices_include_tax', 'no' ) ? 2 : 1 ); $this->define( 'WC_DELIMITER', '|' );