Trim zeros off prices (optional) Closes #297.

This commit is contained in:
Mike Jolley 2011-12-01 11:34:26 +00:00
parent a37c7d5dc8
commit 326bdd400f
5 changed files with 18 additions and 3 deletions

View File

@ -568,6 +568,14 @@ $woocommerce_settings['catalog'] = apply_filters('woocommerce_catalog_settings',
'type' => 'text', 'type' => 'text',
), ),
array(
'name' => __( 'Trim zeros', 'woothemes' ),
'desc' => __( 'Trim zeros after the decimal point when displaying prices', 'woothemes' ),
'id' => 'woocommerce_price_trim_zeros',
'std' => 'yes',
'type' => 'checkbox'
),
array( 'type' => 'sectionend', 'id' => 'pricing_options' ), array( 'type' => 'sectionend', 'id' => 'pricing_options' ),
array( 'name' => __( 'Image Options', 'woothemes' ), 'type' => 'title','desc' => sprintf(__('These settings affect the actual dimensions of images in your catalog - the display on the front-end will still be affected by CSS styles. After changing these settings you may need to <a href="%s">regenerate your thumbnails</a>.', 'woothemes'), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'id' => 'image_options' ), array( 'name' => __( 'Image Options', 'woothemes' ), 'type' => 'title','desc' => sprintf(__('These settings affect the actual dimensions of images in your catalog - the display on the front-end will still be affected by CSS styles. After changing these settings you may need to <a href="%s">regenerate your thumbnails</a>.', 'woothemes'), 'http://wordpress.org/extend/plugins/regenerate-thumbnails/'), 'id' => 'image_options' ),

View File

@ -700,7 +700,7 @@ class woocommerce_checkout {
'name' => $_product->get_title(), 'name' => $_product->get_title(),
'qty' => (int) $values['quantity'], 'qty' => (int) $values['quantity'],
'base_cost' => $_product->get_price_excluding_tax( false ), 'base_cost' => $_product->get_price_excluding_tax( false ),
'cost' => trim(trim(number_format($cost, 4, '.', ''), '0'), '.'), 'cost' => rtrim(rtrim(number_format($cost, 4, '.', ''), '0'), '.'),
'taxrate' => $rate, 'taxrate' => $rate,
'item_meta' => $item_meta->meta 'item_meta' => $item_meta->meta
), $values); ), $values);

View File

@ -596,7 +596,7 @@ class woocommerce_countries {
global $woocommerce; global $woocommerce;
if ( $rate > 0 || $rate === 0 ) : if ( $rate > 0 || $rate === 0 ) :
$rate = trim(trim($rate, '0'), '.'); $rate = rtrim(rtrim($rate, '0'), '.');
if (!$rate) $rate = 0; if (!$rate) $rate = 0;
$return = ( in_array($this->get_base_country(), $this->get_european_union_countries()) ) ? sprintf(__('(inc. %s%% VAT)', 'woothemes'), $rate) : sprintf(__('(inc. %s%% tax)', 'woothemes'), $rate); $return = ( in_array($this->get_base_country(), $this->get_european_union_countries()) ) ? sprintf(__('(inc. %s%% VAT)', 'woothemes'), $rate) : sprintf(__('(inc. %s%% tax)', 'woothemes'), $rate);
else : else :

View File

@ -114,6 +114,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo
* Free shipping/Flat rate uses setting API * Free shipping/Flat rate uses setting API
* Free shipping coupons * Free shipping coupons
* Ship to billing default option * Ship to billing default option
* Trim zeros off prices (optional)
= 1.2.4 - 18/11/2011 = = 1.2.4 - 18/11/2011 =
* More sale price logic fixes for variations. Now correctly compares variation's prices. * More sale price logic fixes for variations. Now correctly compares variation's prices.

View File

@ -469,6 +469,12 @@ function woocommerce_price( $price, $args = array() ) {
$currency_symbol = get_woocommerce_currency_symbol(); $currency_symbol = get_woocommerce_currency_symbol();
$price = number_format( (double) $price, $num_decimals, get_option('woocommerce_price_decimal_sep'), get_option('woocommerce_price_thousand_sep') ); $price = number_format( (double) $price, $num_decimals, get_option('woocommerce_price_decimal_sep'), get_option('woocommerce_price_thousand_sep') );
if (get_option('woocommerce_price_trim_zeros')=='yes') :
$trimmed_price = rtrim(rtrim($price, '0'), get_option('woocommerce_price_decimal_sep'));
$after_decimal = explode(get_option('woocommerce_price_decimal_sep'), $trimmed_price);
if (!isset($after_decimal[1]) || (isset($after_decimal[1]) && (strlen($after_decimal[1]) == 0 && strlen($after_decimal[1]) == $num_decimals))) $price = $trimmed_price;
endif;
switch ($currency_pos) : switch ($currency_pos) :
case 'left' : case 'left' :
$return = $currency_symbol . $price; $return = $currency_symbol . $price;