Functions: wc_price_decimal_separator, wc_price_thousand_separator with defaults.

Closes #7167
This commit is contained in:
Mike Jolley 2015-01-22 16:05:47 +00:00
parent 1dafa5d3cd
commit 6b39849be2
3 changed files with 32 additions and 12 deletions

View File

@ -119,7 +119,7 @@ class WC_Admin_Assets {
// Accounting
wp_localize_script( 'accounting', 'accounting_params', array(
'mon_decimal_point' => get_option( 'woocommerce_price_decimal_sep' )
'mon_decimal_point' => wc_price_decimal_separator()
) );
// WooCommerce admin pages
@ -136,11 +136,11 @@ class WC_Admin_Assets {
$params = array(
'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), get_option( 'woocommerce_price_decimal_sep' ) ),
'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monetary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), wc_price_decimal_separator() ),
'i18n_country_iso_error' => __( 'Please enter in country code with two capital letters.', 'woocommerce' ),
'i18_sale_less_than_regular_error' => __( 'Please enter in a value less than the regular price.', 'woocommerce' ),
'decimal_point' => $decimal,
'mon_decimal_point' => get_option( 'woocommerce_price_decimal_sep' ),
'mon_decimal_point' => wc_price_decimal_separator()
);
// If we're on the profile page and the current user has generated API keys, enqueue and add to $params array
@ -252,8 +252,8 @@ class WC_Admin_Assets {
'base_country' => WC()->countries->get_base_country(),
'currency_format_num_decimals' => absint( get_option( 'woocommerce_price_num_decimals' ) ),
'currency_format_symbol' => get_woocommerce_currency_symbol(),
'currency_format_decimal_sep' => esc_attr( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ) ),
'currency_format_thousand_sep' => esc_attr( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ) ),
'currency_format_decimal_sep' => esc_attr( wc_price_decimal_separator() ),
'currency_format_thousand_sep' => esc_attr( wc_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,
'tax_rounding_mode' => WC_TAX_ROUNDING_MODE,

View File

@ -379,12 +379,12 @@ If enabled on your server, Suhosin may need to be configured to increase its dat
<tr>
<td data-export-label="Thousand Separator"><?php _e( 'Thousand Separator', 'woocommerce' ) ?></td>
<td class="help"><?php echo '<a href="#" class="help_tip" data-tip="' . esc_attr__( 'The thousand separator of displayed prices.', 'woocommerce' ) . '">[?]</a>'; ?></td>
<td><?php echo wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ), ENT_QUOTES ); ?></td>
<td><?php echo wc_price_thousand_separator(); ?></td>
</tr>
<tr>
<td data-export-label="Decimal Separator"><?php _e( 'Decimal Separator', 'woocommerce' ) ?></td>
<td class="help"><?php echo '<a href="#" class="help_tip" data-tip="' . esc_attr__( 'The decimal separator of displayed prices.', 'woocommerce' ) . '">[?]</a>'; ?></td>
<td><?php echo wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ), ENT_QUOTES ); ?></td>
<td><?php echo wc_price_decimal_separator(); ?></td>
</tr>
<tr>
<td data-export-label="Number of Decimals"><?php _e( 'Number of Decimals', 'woocommerce' ) ?></td>

View File

@ -142,7 +142,7 @@ function wc_get_weight( $weight, $to_unit ) {
* @return string
*/
function wc_trim_zeros( $price ) {
return preg_replace( '/' . preg_quote( get_option( 'woocommerce_price_decimal_sep' ), '/' ) . '0++$/', '', $price );
return preg_replace( '/' . preg_quote( wc_price_decimal_separator(), '/' ) . '0++$/', '', $price );
}
/**
@ -184,7 +184,7 @@ function wc_format_refund_total( $amount ) {
*/
function wc_format_decimal( $number, $dp = false, $trim_zeros = false ) {
$locale = localeconv();
$decimals = array( get_option( 'woocommerce_price_decimal_sep' ), $locale['decimal_point'], $locale['mon_decimal_point'] );
$decimals = array( wc_price_decimal_separator(), $locale['decimal_point'], $locale['mon_decimal_point'] );
// Remove locale from string
if ( ! is_float( $number ) ) {
@ -230,7 +230,7 @@ function wc_float_to_string( $float ) {
* @return string
*/
function wc_format_localized_price( $value ) {
return str_replace( '.', get_option( 'woocommerce_price_decimal_sep' ), strval( $value ) );
return str_replace( '.', wc_price_decimal_separator(), strval( $value ) );
}
/**
@ -309,6 +309,26 @@ function get_woocommerce_price_format() {
return apply_filters( 'woocommerce_price_format', $format, $currency_pos );
}
/**
* Return the thousand separator for prices
* @since 2.3
* @return string
*/
function wc_price_thousand_separator() {
$separator = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ), ENT_QUOTES );
return $separator;
}
/**
* Return the decimal separator for prices
* @since 2.3
* @return string
*/
function wc_price_decimal_separator() {
$separator = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ), ENT_QUOTES );
return $separator ? $separator : '.';
}
/**
* Format the price with a currency symbol.
*
@ -324,8 +344,8 @@ function wc_price( $price, $args = array() ) {
$num_decimals = absint( get_option( 'woocommerce_price_num_decimals' ) );
$currency = isset( $args['currency'] ) ? $args['currency'] : '';
$currency_symbol = get_woocommerce_currency_symbol($currency);
$decimal_sep = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ), ENT_QUOTES );
$thousands_sep = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ), ENT_QUOTES );
$decimal_sep = wc_price_decimal_separator();
$thousands_sep = wc_price_thousand_separator();
if ( $price < 0 ) {
$price = $price * -1;