From f8ea5ed28102ff15d48e047f6b351a5049db04c1 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Sat, 28 Jan 2012 15:20:27 +0000 Subject: [PATCH] Regex trim zeros back --- admin/post-types/writepanels/writepanel-order_data.php | 8 ++++---- classes/class-wc-checkout.php | 8 ++++---- woocommerce-core-functions.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/admin/post-types/writepanels/writepanel-order_data.php b/admin/post-types/writepanels/writepanel-order_data.php index e84380ff4c7..5b826021d24 100644 --- a/admin/post-types/writepanels/writepanel-order_data.php +++ b/admin/post-types/writepanels/writepanel-order_data.php @@ -716,10 +716,10 @@ function woocommerce_process_shop_order_meta( $post_id, $post ) { 'variation_id' => (int) $item_variation[$i], 'name' => htmlspecialchars(stripslashes($item_name[$i])), 'qty' => (int) $item_quantity[$i], - 'line_total' => woocommerce_trim_zeros(number_format(woocommerce_clean($line_total[$i]), 4, '.', '')), - 'line_tax' => woocommerce_trim_zeros(number_format(woocommerce_clean($line_tax[$i]), 4, '.', '')), - 'line_subtotal' => woocommerce_trim_zeros(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', '')), - 'line_subtotal_tax' => woocommerce_trim_zeros(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', '')), + 'line_total' => rtrim(rtrim(number_format(woocommerce_clean($line_total[$i]), 4, '.', '')), '0'), '.'), + 'line_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_tax[$i]), 4, '.', '')), '0'), '.'), + 'line_subtotal' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', '')), '0'), '.'), + 'line_subtotal_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', '')), '0'), '.'), 'item_meta' => $item_meta->meta, 'tax_class' => woocommerce_clean($item_tax_class[$i]) )); diff --git a/classes/class-wc-checkout.php b/classes/class-wc-checkout.php index 2b12b064764..0480080f602 100644 --- a/classes/class-wc-checkout.php +++ b/classes/class-wc-checkout.php @@ -406,10 +406,10 @@ class WC_Checkout { 'name' => $_product->get_title(), 'qty' => (int) $values['quantity'], 'item_meta' => $item_meta->meta, - 'line_subtotal' => woocommerce_trim_zeros(number_format($values['line_subtotal'], 4, '.', '')), // Line subtotal (before discounts) - 'line_subtotal_tax' => woocommerce_trim_zeros(number_format($values['line_subtotal_tax'], 4, '.', '')), // Line tax (before discounts) - 'line_total' => woocommerce_trim_zeros(number_format($values['line_total'], 4, '.', '')), // Line total (after discounts) - 'line_tax' => woocommerce_trim_zeros(number_format($values['line_tax'], 4, '.', '')), // Line Tax (after discounts) + 'line_subtotal' => rtrim(rtrim(number_format($values['line_subtotal'], 4, '.', '')), '0'), '.'), // Line subtotal (before discounts) + 'line_subtotal_tax' => rtrim(rtrim(number_format($values['line_subtotal_tax'], 4, '.', '')), '0'), '.'), // Line tax (before discounts) + 'line_total' => rtrim(rtrim(number_format($values['line_total'], 4, '.', '')), '0'), '.'), // Line total (after discounts) + 'line_tax' => rtrim(rtrim(number_format($values['line_tax'], 4, '.', '')), '0'), '.'), // Line Tax (after discounts) 'tax_class' => $_product->get_tax_class() // Tax class (adjusted by filters) ), $values); endforeach; diff --git a/woocommerce-core-functions.php b/woocommerce-core-functions.php index 6a972b22d40..ebc434a3f31 100644 --- a/woocommerce-core-functions.php +++ b/woocommerce-core-functions.php @@ -189,7 +189,7 @@ function woocommerce_price( $price, $args = array() ) { * Trim trailing zeros **/ function woocommerce_trim_zeros( $price ) { - return rtrim(rtrim($price, '0'), '.'); + return preg_replace('/'.preg_quote(get_option('woocommerce_price_decimal_sep'), '/').'0++$/', '', $price); } /**