Regex trim zeros back
This commit is contained in:
parent
c57ab7c33f
commit
f8ea5ed281
|
@ -716,10 +716,10 @@ function woocommerce_process_shop_order_meta( $post_id, $post ) {
|
||||||
'variation_id' => (int) $item_variation[$i],
|
'variation_id' => (int) $item_variation[$i],
|
||||||
'name' => htmlspecialchars(stripslashes($item_name[$i])),
|
'name' => htmlspecialchars(stripslashes($item_name[$i])),
|
||||||
'qty' => (int) $item_quantity[$i],
|
'qty' => (int) $item_quantity[$i],
|
||||||
'line_total' => woocommerce_trim_zeros(number_format(woocommerce_clean($line_total[$i]), 4, '.', '')),
|
'line_total' => rtrim(rtrim(number_format(woocommerce_clean($line_total[$i]), 4, '.', '')), '0'), '.'),
|
||||||
'line_tax' => woocommerce_trim_zeros(number_format(woocommerce_clean($line_tax[$i]), 4, '.', '')),
|
'line_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_tax[$i]), 4, '.', '')), '0'), '.'),
|
||||||
'line_subtotal' => woocommerce_trim_zeros(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', '')),
|
'line_subtotal' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal[$i]), 4, '.', '')), '0'), '.'),
|
||||||
'line_subtotal_tax' => woocommerce_trim_zeros(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', '')),
|
'line_subtotal_tax' => rtrim(rtrim(number_format(woocommerce_clean($line_subtotal_tax[$i]), 4, '.', '')), '0'), '.'),
|
||||||
'item_meta' => $item_meta->meta,
|
'item_meta' => $item_meta->meta,
|
||||||
'tax_class' => woocommerce_clean($item_tax_class[$i])
|
'tax_class' => woocommerce_clean($item_tax_class[$i])
|
||||||
));
|
));
|
||||||
|
|
|
@ -406,10 +406,10 @@ class WC_Checkout {
|
||||||
'name' => $_product->get_title(),
|
'name' => $_product->get_title(),
|
||||||
'qty' => (int) $values['quantity'],
|
'qty' => (int) $values['quantity'],
|
||||||
'item_meta' => $item_meta->meta,
|
'item_meta' => $item_meta->meta,
|
||||||
'line_subtotal' => woocommerce_trim_zeros(number_format($values['line_subtotal'], 4, '.', '')), // Line subtotal (before discounts)
|
'line_subtotal' => rtrim(rtrim(number_format($values['line_subtotal'], 4, '.', '')), '0'), '.'), // Line subtotal (before discounts)
|
||||||
'line_subtotal_tax' => woocommerce_trim_zeros(number_format($values['line_subtotal_tax'], 4, '.', '')), // Line tax (before discounts)
|
'line_subtotal_tax' => rtrim(rtrim(number_format($values['line_subtotal_tax'], 4, '.', '')), '0'), '.'), // Line tax (before discounts)
|
||||||
'line_total' => woocommerce_trim_zeros(number_format($values['line_total'], 4, '.', '')), // Line total (after discounts)
|
'line_total' => rtrim(rtrim(number_format($values['line_total'], 4, '.', '')), '0'), '.'), // Line total (after discounts)
|
||||||
'line_tax' => woocommerce_trim_zeros(number_format($values['line_tax'], 4, '.', '')), // Line Tax (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)
|
'tax_class' => $_product->get_tax_class() // Tax class (adjusted by filters)
|
||||||
), $values);
|
), $values);
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
|
@ -189,7 +189,7 @@ function woocommerce_price( $price, $args = array() ) {
|
||||||
* Trim trailing zeros
|
* Trim trailing zeros
|
||||||
**/
|
**/
|
||||||
function woocommerce_trim_zeros( $price ) {
|
function woocommerce_trim_zeros( $price ) {
|
||||||
return rtrim(rtrim($price, '0'), '.');
|
return preg_replace('/'.preg_quote(get_option('woocommerce_price_decimal_sep'), '/').'0++$/', '', $price);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue