Locales - store standardised values, and display using locale in admin #3862

This commit is contained in:
Mike Jolley 2013-11-12 17:43:30 +00:00
parent 6bcee46ffb
commit 3fd02a57d0
31 changed files with 658 additions and 574 deletions

View File

@ -309,12 +309,12 @@ jQuery( function($){
$('#woocommerce-order-totals').on( 'change input', '.order_taxes_amount, .order_taxes_shipping_amount, .shipping_cost, #_order_discount', function() {
var $this = $(this);
var fields = $this.closest('.totals_group').find('input[type=number], .wc_input_decimal');
var fields = $this.closest('.totals_group').find('input[type=number], .wc_input_price');
var total = 0;
fields.each(function(){
if ( $(this).val() )
total = total + parseFloat( $(this).val() );
total = total + accounting.unformat( $(this).val(), woocommerce_admin.mon_decimal_point );
});
if ( $this.is('.order_taxes_amount') || $this.is('.order_taxes_shipping_amount') ) {
@ -385,9 +385,9 @@ jQuery( function($){
order_shipping = 0;
$('#shipping_rows').find('input[type=number], .wc_input_decimal').each(function(){
$('#shipping_rows').find('input[type=number], .wc_input_price').each(function(){
cost = $(this).val() || '0';
cost = accounting.unformat( cost.replace(',', '.') );
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
order_shipping = order_shipping + parseFloat( cost );
});
@ -449,15 +449,15 @@ jQuery( function($){
order_discount = accounting.unformat( order_discount.replace(',', '.') );
$('#shipping_rows').find('input[type=number], .wc_input_decimal').each(function(){
$('#shipping_rows').find('input[type=number], .wc_input_price').each(function(){
cost = $(this).val() || '0';
cost = accounting.unformat( cost.replace(',', '.') );
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
shipping = shipping + parseFloat( cost );
});
$('#tax_rows').find('input[type=number], .wc_input_decimal').each(function(){
$('#tax_rows').find('input[type=number], .wc_input_price').each(function(){
cost = $(this).val() || '0';
cost = accounting.unformat( cost.replace(',', '.') );
cost = accounting.unformat( cost, woocommerce_admin.mon_decimal_point );
tax = tax + parseFloat( cost );
});
@ -471,7 +471,7 @@ jQuery( function($){
tax = parseFloat( accounting.toFixed( tax, woocommerce_admin_meta_boxes.rounding_precision ) );
// Set Total
$('#_order_total').val( parseFloat( accounting.toFixed( line_totals + tax + shipping - order_discount, woocommerce_admin_meta_boxes.currency_format_num_decimals ) ) ).change();
$('#_order_total').val( accounting.formatNumber( line_totals + tax + shipping - order_discount, woocommerce_admin_meta_boxes.currency_format_num_decimals, '', woocommerce_admin.mon_decimal_point ) ).change();
}
$('#woocommerce-order-totals').unblock();

File diff suppressed because one or more lines are too long

View File

@ -3,24 +3,44 @@
*/
jQuery(function(){
// Price input validation - Keep price inputs formatted correctly
jQuery(".wc_input_decimal[type=text]")
.each(function(){
var value = jQuery(this).val();
var newvalue = value.replace( '.', woocommerce_admin.locale_decimal_point );
jQuery(this).val( newvalue );
// Price input validation
jQuery(".wc_input_decimal[type=text], .wc_input_price[type=text]")
.bind( 'blur', function() {
jQuery('.wc_error_tip').fadeOut('100', function(){ jQuery(this).remove(); } );
return this;
});
jQuery(".wc_input_decimal[type=text]")
jQuery(".wc_input_price[type=text]")
.bind( 'keyup change', function() {
var value = jQuery(this).val();
var regex = new RegExp( "[^0-9\%.\\" + woocommerce_admin.locale_decimal_point + "]+", "gi" );
var regex = new RegExp( "[^0-9\%.\\" + woocommerce_admin.mon_decimal_point + "]+", "gi" );
var newvalue = value.replace( regex, '' );
if ( value !== newvalue ) {
jQuery(this).val( newvalue );
if ( jQuery(this).parent().find('.wc_error_tip').size() == 0 ) {
var offset = jQuery(this).position();
jQuery(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_decimal_input_error + '</div>' );
jQuery(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_mon_decimal_error + '</div>' );
jQuery('.wc_error_tip')
.css('left', offset.left + jQuery(this).width() - ( jQuery(this).width() / 2 ) - ( jQuery('.wc_error_tip').width() / 2 ) )
.css('top', offset.top + jQuery(this).height() )
.fadeIn('100');
}
}
return this;
});
jQuery(".wc_input_decimal[type=text]")
.bind( 'keyup change', function() {
var value = jQuery(this).val();
var regex = new RegExp( "[^0-9\%.\\" + woocommerce_admin.decimal_point + "]+", "gi" );
var newvalue = value.replace( regex, '' );
if ( value !== newvalue ) {
jQuery(this).val( newvalue );
if ( jQuery(this).parent().find('.wc_error_tip').size() == 0 ) {
var offset = jQuery(this).position();
jQuery(this).after( '<div class="wc_error_tip">' + woocommerce_admin.i18n_decimal_error + '</div>' );
jQuery('.wc_error_tip')
.css('left', offset.left + jQuery(this).width() - ( jQuery(this).width() / 2 ) - ( jQuery('.wc_error_tip').width() / 2 ) )
.css('top', offset.top + jQuery(this).height() )
@ -28,10 +48,6 @@ jQuery(function(){
}
}
return this;
})
.bind( 'blur', function() {
jQuery('.wc_error_tip').fadeOut('100', function(){ jQuery(this).remove(); } );
return this;
});
jQuery("body").click(function(){

View File

@ -1,3 +1,3 @@
/**
* WooCommerce Admin JS
*/jQuery(function(){jQuery(".wc_input_decimal[type=text]").each(function(){var e=jQuery(this).val(),t=e.replace(".",woocommerce_admin.locale_decimal_point);jQuery(this).val(t)});jQuery(".wc_input_decimal[type=text]").bind("keyup change",function(){var e=jQuery(this).val(),t=new RegExp("[^0-9%.\\"+woocommerce_admin.locale_decimal_point+"]+","gi"),n=e.replace(t,"");if(e!==n){jQuery(this).val(n);if(jQuery(this).parent().find(".wc_error_tip").size()==0){var r=jQuery(this).position();jQuery(this).after('<div class="wc_error_tip">'+woocommerce_admin.i18n_decimal_input_error+"</div>");jQuery(".wc_error_tip").css("left",r.left+jQuery(this).width()-jQuery(this).width()/2-jQuery(".wc_error_tip").width()/2).css("top",r.top+jQuery(this).height()).fadeIn("100")}}return this}).bind("blur",function(){jQuery(".wc_error_tip").fadeOut("100",function(){jQuery(this).remove()});return this});jQuery("body").click(function(){jQuery(".wc_error_tip").fadeOut("100",function(){jQuery(this).remove()})});jQuery(".tips, .help_tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200});jQuery(".wc_input_table.sortable tbody").sortable({items:"tr",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style")}});jQuery(".wc_input_table .remove_rows").click(function(){var e=jQuery(this).closest(".wc_input_table").find("tbody");if(e.find("tr.current").size()>0){$current=e.find("tr.current");$current.each(function(){jQuery(this).remove()})}return!1});var e=!1,t=!1,n=!1;jQuery(document).bind("keyup keydown",function(n){t=n.shiftKey;e=n.ctrlKey||n.metaKey});jQuery(".wc_input_table").on("focus click","input",function(r){$this_table=jQuery(this).closest("table");$this_row=jQuery(this).closest("tr");if(r.type=="focus"&&n!=$this_row.index()||r.type=="click"&&jQuery(this).is(":focus")){n=$this_row.index();if(!t&&!e){jQuery("tr",$this_table).removeClass("current").removeClass("last_selected");$this_row.addClass("current").addClass("last_selected")}else if(t){jQuery("tr",$this_table).removeClass("current");$this_row.addClass("selected_now").addClass("current");jQuery("tr.last_selected",$this_table).size()>0&&($this_row.index()>jQuery("tr.last_selected, $this_table").index()?jQuery("tr",$this_table).slice(jQuery("tr.last_selected",$this_table).index(),$this_row.index()).addClass("current"):jQuery("tr",$this_table).slice($this_row.index(),jQuery("tr.last_selected",$this_table).index()+1).addClass("current"));jQuery("tr",$this_table).removeClass("last_selected");$this_row.addClass("last_selected")}else{jQuery("tr",$this_table).removeClass("last_selected");e&&jQuery(this).closest("tr").is(".current")?$this_row.removeClass("current"):$this_row.addClass("current").addClass("last_selected")}jQuery("tr",$this_table).removeClass("selected_now")}}).on("blur","input",function(e){n=!1});jQuery("select.availability").change(function(){jQuery(this).val()=="all"?jQuery(this).closest("tr").next("tr").hide():jQuery(this).closest("tr").next("tr").show()}).change();jQuery("body").on("click",".show_order_items",function(){jQuery(this).closest("td").find("table").toggle();return!1});jQuery(".hide_options_if_checked").each(function(){jQuery(this).find("input:eq(0)").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide():jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show()}).change()});jQuery(".show_options_if_checked").each(function(){jQuery(this).find("input:eq(0)").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show():jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide()}).change()});jQuery("input#woocommerce_demo_store").change(function(){jQuery(this).is(":checked")?jQuery("#woocommerce_demo_store_notice").closest("tr").show():jQuery("#woocommerce_demo_store_notice").closest("tr").hide()}).change()});
*/jQuery(function(){jQuery(".wc_input_decimal[type=text], .wc_input_price[type=text]").bind("blur",function(){jQuery(".wc_error_tip").fadeOut("100",function(){jQuery(this).remove()});return this});jQuery(".wc_input_price[type=text]").bind("keyup change",function(){var e=jQuery(this).val(),t=new RegExp("[^0-9%.\\"+woocommerce_admin.mon_decimal_point+"]+","gi"),n=e.replace(t,"");if(e!==n){jQuery(this).val(n);if(jQuery(this).parent().find(".wc_error_tip").size()==0){var r=jQuery(this).position();jQuery(this).after('<div class="wc_error_tip">'+woocommerce_admin.i18n_mon_decimal_error+"</div>");jQuery(".wc_error_tip").css("left",r.left+jQuery(this).width()-jQuery(this).width()/2-jQuery(".wc_error_tip").width()/2).css("top",r.top+jQuery(this).height()).fadeIn("100")}}return this});jQuery(".wc_input_decimal[type=text]").bind("keyup change",function(){var e=jQuery(this).val(),t=new RegExp("[^0-9%.\\"+woocommerce_admin.decimal_point+"]+","gi"),n=e.replace(t,"");if(e!==n){jQuery(this).val(n);if(jQuery(this).parent().find(".wc_error_tip").size()==0){var r=jQuery(this).position();jQuery(this).after('<div class="wc_error_tip">'+woocommerce_admin.i18n_decimal_error+"</div>");jQuery(".wc_error_tip").css("left",r.left+jQuery(this).width()-jQuery(this).width()/2-jQuery(".wc_error_tip").width()/2).css("top",r.top+jQuery(this).height()).fadeIn("100")}}return this});jQuery("body").click(function(){jQuery(".wc_error_tip").fadeOut("100",function(){jQuery(this).remove()})});jQuery(".tips, .help_tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200});jQuery(".wc_input_table.sortable tbody").sortable({items:"tr",cursor:"move",axis:"y",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65,placeholder:"wc-metabox-sortable-placeholder",start:function(e,t){t.item.css("background-color","#f6f6f6")},stop:function(e,t){t.item.removeAttr("style")}});jQuery(".wc_input_table .remove_rows").click(function(){var e=jQuery(this).closest(".wc_input_table").find("tbody");if(e.find("tr.current").size()>0){$current=e.find("tr.current");$current.each(function(){jQuery(this).remove()})}return!1});var e=!1,t=!1,n=!1;jQuery(document).bind("keyup keydown",function(n){t=n.shiftKey;e=n.ctrlKey||n.metaKey});jQuery(".wc_input_table").on("focus click","input",function(r){$this_table=jQuery(this).closest("table");$this_row=jQuery(this).closest("tr");if(r.type=="focus"&&n!=$this_row.index()||r.type=="click"&&jQuery(this).is(":focus")){n=$this_row.index();if(!t&&!e){jQuery("tr",$this_table).removeClass("current").removeClass("last_selected");$this_row.addClass("current").addClass("last_selected")}else if(t){jQuery("tr",$this_table).removeClass("current");$this_row.addClass("selected_now").addClass("current");jQuery("tr.last_selected",$this_table).size()>0&&($this_row.index()>jQuery("tr.last_selected, $this_table").index()?jQuery("tr",$this_table).slice(jQuery("tr.last_selected",$this_table).index(),$this_row.index()).addClass("current"):jQuery("tr",$this_table).slice($this_row.index(),jQuery("tr.last_selected",$this_table).index()+1).addClass("current"));jQuery("tr",$this_table).removeClass("last_selected");$this_row.addClass("last_selected")}else{jQuery("tr",$this_table).removeClass("last_selected");e&&jQuery(this).closest("tr").is(".current")?$this_row.removeClass("current"):$this_row.addClass("current").addClass("last_selected")}jQuery("tr",$this_table).removeClass("selected_now")}}).on("blur","input",function(e){n=!1});jQuery("select.availability").change(function(){jQuery(this).val()=="all"?jQuery(this).closest("tr").next("tr").hide():jQuery(this).closest("tr").next("tr").show()}).change();jQuery("body").on("click",".show_order_items",function(){jQuery(this).closest("td").find("table").toggle();return!1});jQuery(".hide_options_if_checked").each(function(){jQuery(this).find("input:eq(0)").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide():jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show()}).change()});jQuery(".show_options_if_checked").each(function(){jQuery(this).find("input:eq(0)").change(function(){jQuery(this).is(":checked")?jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").show():jQuery(this).closest("fieldset, tr").nextUntil(".hide_options_if_checked, .show_options_if_checked",".hidden_option").hide()}).change()});jQuery("input#woocommerce_demo_store").change(function(){jQuery(this).is(":checked")?jQuery("#woocommerce_demo_store_notice").closest("tr").show():jQuery("#woocommerce_demo_store_notice").closest("tr").hide()}).change()});

View File

@ -3,7 +3,7 @@
* Admin Settings API used by Shipping Methods and Payment Gateways
*
* @class WC_Settings_API
* @version 2.0.0
* @version 2.1.0
* @package WooCommerce/Abstracts
* @category Abstract Class
* @author WooThemes
@ -45,7 +45,6 @@ abstract class WC_Settings_API {
</table><?php
}
/**
* Initialise Settings Form Fields
*
@ -58,7 +57,6 @@ abstract class WC_Settings_API {
*/
public function init_form_fields() {}
/**
* Admin Panel Options Processing
* - Saves the options to the DB
@ -80,7 +78,6 @@ abstract class WC_Settings_API {
}
}
/**
* Display admin error messages.
*
@ -90,7 +87,6 @@ abstract class WC_Settings_API {
*/
public function display_errors() {}
/**
* Initialise Gateway Settings
*
@ -123,7 +119,6 @@ abstract class WC_Settings_API {
}
}
/**
* get_option function.
*
@ -135,7 +130,6 @@ abstract class WC_Settings_API {
* @return string The value specified for the option or a default value for the option
*/
public function get_option( $key, $empty_value = null ) {
if ( empty( $this->settings ) )
$this->init_settings();
@ -150,7 +144,6 @@ abstract class WC_Settings_API {
return $this->settings[ $key ];
}
/**
* Decode values for settings.
*
@ -159,10 +152,9 @@ abstract class WC_Settings_API {
* @return array
*/
public function format_settings( $value ) {
return ( is_array( $value ) ) ? $value : $value;
return is_array( $value ) ? $value : $value;
}
/**
* Generate Settings HTML.
*
@ -175,11 +167,9 @@ abstract class WC_Settings_API {
* @access public
* @return string the html for the settings
*/
public function generate_settings_html ( $form_fields = false ) {
if ( ! $form_fields ) {
public function generate_settings_html( $form_fields = false ) {
if ( ! $form_fields )
$form_fields = $this->form_fields;
}
$html = '';
foreach ( $form_fields as $k => $v ) {
@ -196,6 +186,56 @@ abstract class WC_Settings_API {
echo $html;
}
/**
* Get HTML for tooltips
* @param array $data
* @return string
*/
public function get_tooltip_html( $data ) {
if ( $data['desc_tip'] === true ) {
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$tip = $data['desc_tip'];
} else {
$tip = '';
}
return $tip ? '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . WC()->plugin_url() . '/assets/images/help.png" height="16" width="16" />' : '';
}
/**
* Get HTML for descriptions
* @param array $data
* @return string
*/
public function get_description_html( $data ) {
if ( $data['desc_tip'] === true ) {
$description = '';
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
} else {
$description = '';
}
return $description ? '<p class="description">' . wp_kses_post( $description ) . '</p>' . "\n" : '';
}
/**
* Get custom attributes
* @param array $data
* @return string
*/
public function get_custom_attribute_html( $data ) {
$custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
return implode( ' ', $custom_attributes );
}
/**
* Generate Text Input HTML.
@ -207,60 +247,126 @@ abstract class WC_Settings_API {
* @return string
*/
public function generate_text_html( $key, $data ) {
global $woocommerce;
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
'title' => '',
'disabled' => false,
'class' => '',
'css' => '',
'placeholder' => '',
'type' => 'text',
'desc_tip' => false,
'description' => '',
'custom_attributes' => array()
);
$html = '';
$data = wp_parse_args( $data, $defaults );
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['placeholder'] = isset( $data['placeholder'] ) ? $data['placeholder'] : '';
$data['type'] = isset( $data['type'] ) ? $data['type'] : 'text';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<input class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
}
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
/**
* Generate Password Input HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.0.0
* @return string
*/
public function generate_price_html( $key, $data ) {
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
'title' => '',
'disabled' => false,
'class' => '',
'css' => '',
'placeholder' => '',
'type' => 'text',
'desc_tip' => false,
'description' => '',
'custom_attributes' => array()
);
// Custom attribute handling
$custom_attributes = array();
$data = wp_parse_args( $data, $defaults );
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<input class="wc_input_price input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
}
$html .= '<tr valign="top">' . "\n";
$html .= '<th scope="row" class="titledesc">';
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
/**
* Generate Password Input HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.0.0
* @return string
*/
public function generate_decimal_html( $key, $data ) {
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
'title' => '',
'disabled' => false,
'class' => '',
'css' => '',
'placeholder' => '',
'type' => 'text',
'desc_tip' => false,
'description' => '',
'custom_attributes' => array()
);
if ( $tip )
$html .= '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
$data = wp_parse_args( $data, $defaults );
$html .= '</th>' . "\n";
$html .= '<td class="forminp">' . "\n";
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
$html .= '<input class="input-text regular-input ' . esc_attr( $data['class'] ) . '" type="' . esc_attr( $data['type'] ) . '" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" style="' . esc_attr( $data['css'] ) . '" value="' . esc_attr( $this->get_option( $key ) ) . '" placeholder="' . esc_attr( $data['placeholder'] ) . '" ' . disabled( $data['disabled'], true, false ) . ' ' . implode( ' ', $custom_attributes ) . ' />';
if ( $description )
$html .= ' <p class="description">' . wp_kses_post( $description ) . '</p>' . "\n";
$html .= '</fieldset>';
$html .= '</td>' . "\n";
$html .= '</tr>' . "\n";
return $html;
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<input class="wc_input_decimal input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_decimal( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
}
/**
@ -273,58 +379,8 @@ abstract class WC_Settings_API {
* @return string
*/
public function generate_password_html( $key, $data ) {
global $woocommerce;
$html = '';
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
$html .= '<tr valign="top">' . "\n";
$html .= '<th scope="row" class="titledesc">';
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
if ( $tip )
$html .= '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
$html .= '</th>' . "\n";
$html .= '<td class="forminp">' . "\n";
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
$html .= '<input class="input-text regular-input ' . esc_attr( $data['class'] ) . '" type="password" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" style="' . esc_attr( $data['css'] ) . '" value="' . esc_attr( $this->get_option( $key ) ) . '" ' . disabled( $data['disabled'], true, false ) . ' ' . implode( ' ', $custom_attributes ) . ' />';
if ( $description )
$html .= ' <p class="description">' . wp_kses_post( $description ) . '</p>' . "\n";
$html .= '</fieldset>';
$html .= '</td>' . "\n";
$html .= '</tr>' . "\n";
return $html;
$data['type'] = 'password';
return $this->generate_text_html( $key, $data );
}
/**
@ -337,59 +393,38 @@ abstract class WC_Settings_API {
* @return string
*/
public function generate_textarea_html( $key, $data ) {
global $woocommerce;
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
'title' => '',
'disabled' => false,
'class' => '',
'css' => '',
'placeholder' => '',
'type' => 'text',
'desc_tip' => false,
'description' => '',
'custom_attributes' => array()
);
$html = '';
$data = wp_parse_args( $data, $defaults );
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
$data['placeholder'] = isset( $data['placeholder'] ) ? $data['placeholder'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
$html .= '<tr valign="top">' . "\n";
$html .= '<th scope="row" class="titledesc">';
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
if ( $tip )
$html .= '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
$html .= '</th>' . "\n";
$html .= '<td class="forminp">' . "\n";
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
$html .= '<textarea rows="3" cols="20" class="input-text wide-input ' . esc_attr( $data['class'] ) . '" placeholder="' . esc_attr( $data['placeholder'] ) . '" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" style="' . esc_attr( $data['css'] ) . '" ' . disabled( $data['disabled'], true, false ) . ' ' . implode( ' ', $custom_attributes ) . '>' . esc_textarea( $this->get_option( $key ) ) . '</textarea>';
if ( $description )
$html .= ' <p class="description">' . wp_kses_post( $description ) . '</p>' . "\n";
$html .= '</fieldset>';
$html .= '</td>' . "\n";
$html .= '</tr>' . "\n";
return $html;
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<textarea rows="3" cols="20" class="input-text wide-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo esc_textarea( $this->get_option( $key ) ); ?></textarea>
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
}
/**
@ -402,59 +437,42 @@ abstract class WC_Settings_API {
* @return string
*/
public function generate_checkbox_html( $key, $data ) {
global $woocommerce;
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
'title' => '',
'label' => '',
'disabled' => false,
'class' => '',
'css' => '',
'type' => 'text',
'desc_tip' => false,
'description' => '',
'custom_attributes' => array()
);
$html = '';
$data = wp_parse_args( $data, $defaults );
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['label'] = isset( $data['label'] ) ? $data['label'] : $data['title'];
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
if ( ! $data['label'] )
$data['label'] = $data['title'];
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
$html .= '<tr valign="top">' . "\n";
$html .= '<th scope="row" class="titledesc">' . $data['title'];
if ( $tip )
$html .= '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
$html .= '</th>' . "\n";
$html .= '<td class="forminp">' . "\n";
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">';
$html .= '<input style="' . esc_attr( $data['css'] ) . '" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" type="checkbox" value="1" ' . checked( $this->get_option( $key ), 'yes', false ) . ' class="' . esc_attr( $data['class'] ).'" ' . disabled( $data['disabled'], true, false ) . ' ' . implode( ' ', $custom_attributes ) . ' /> ' . wp_kses_post( $data['label'] ) . '</label><br />' . "\n";
if ( $description )
$html .= ' <p class="description">' . wp_kses_post( $description ) . '</p>' . "\n";
$html .= '</fieldset>';
$html .= '</td>' . "\n";
$html .= '</tr>' . "\n";
return $html;
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<label for="<?php echo esc_attr( $field ); ?>">
<input class="<?php echo esc_attr( $data['class'] ); ?>" type="checkbox" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="1" <?php checked( $this->get_option( $key ), 'yes' ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> <?php echo wp_kses_post( $data['label'] ); ?></label><br/>
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
}
/**
@ -467,65 +485,43 @@ abstract class WC_Settings_API {
* @return string
*/
public function generate_select_html( $key, $data ) {
global $woocommerce;
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
'title' => '',
'disabled' => false,
'class' => '',
'css' => '',
'placeholder' => '',
'type' => 'text',
'desc_tip' => false,
'description' => '',
'custom_attributes' => array(),
'options' => array()
);
$html = '';
$data = wp_parse_args( $data, $defaults );
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['options'] = isset( $data['options'] ) ? (array) $data['options'] : array();
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
$html .= '<tr valign="top">' . "\n";
$html .= '<th scope="row" class="titledesc">';
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
if ( $tip )
$html .= '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
$html .= '</th>' . "\n";
$html .= '<td class="forminp">' . "\n";
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
$html .= '<select name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" style="' . esc_attr( $data['css'] ) . '" class="select ' .esc_attr( $data['class'] ) . '" ' . disabled( $data['disabled'], true, false ) . ' ' . implode( ' ', $custom_attributes ) . '>';
foreach ($data['options'] as $option_key => $option_value) :
$html .= '<option value="' . esc_attr( $option_key ) . '" '.selected( $option_key, esc_attr( $this->get_option( $key ) ), false ).'>' . esc_attr( $option_value ) . '</option>';
endforeach;
$html .= '</select>';
if ( $description )
$html .= ' <p class="description">' . wp_kses_post( $description ) . '</p>' . "\n";
$html .= '</fieldset>';
$html .= '</td>' . "\n";
$html .= '</tr>' . "\n";
return $html;
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<select class="select <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>>
<?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $option_key, esc_attr( $this->get_option( $key ) ) ); ?>><?php echo esc_attr( $option_value ); ?></option>
<?php endforeach; ?>
</select>
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
}
/**
@ -538,65 +534,42 @@ abstract class WC_Settings_API {
* @return string
*/
public function generate_multiselect_html( $key, $data ) {
global $woocommerce;
$field = $this->plugin_id . $this->id . '_' . $key;
$defaults = array(
'title' => '',
'disabled' => false,
'class' => '',
'placeholder' => '',
'type' => 'text',
'desc_tip' => false,
'description' => '',
'custom_attributes' => array(),
'options' => array()
);
$html = '';
$data = wp_parse_args( $data, $defaults );
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['options'] = isset( $data['options'] ) ? (array) $data['options'] : array();
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$custom_attributes = array();
if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) )
foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
$html .= '<tr valign="top">' . "\n";
$html .= '<th scope="row" class="titledesc">';
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
if ( $tip )
$html .= '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . $woocommerce->plugin_url() . '/assets/images/help.png" height="16" width="16" />';
$html .= '</th>' . "\n";
$html .= '<td class="forminp">' . "\n";
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
$html .= '<select multiple="multiple" style="' . esc_attr( $data['css'] ) . '" class="multiselect ' . esc_attr( $data['class'] ) . '" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '[]" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" ' . disabled( $data['disabled'], true, false ) . ' ' . implode( ' ', $custom_attributes ) . '>';
foreach ( $data['options'] as $option_key => $option_value) {
$html .= '<option value="' . esc_attr( $option_key ) . '" ' . selected( in_array( $option_key, $this->get_option( $key, array() ) ), true, false ) . '>' . esc_attr( $option_value ) . '</option>';
}
$html .= '</select>';
if ( $description )
$html .= ' <p class="description">' . wp_kses_post( $description ) . '</p>' . "\n";
$html .= '</fieldset>';
$html .= '</td>' . "\n";
$html .= '</tr>' . "\n";
return $html;
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
<?php echo $this->get_tooltip_html( $data ); ?>
</th>
<td class="forminp">
<fieldset>
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
<select multiple="multiple" class="multiselect <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field ); ?>[]" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>>
<?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $option_key, esc_attr( $this->get_option( $key ) ) ); ?>><?php echo esc_attr( $option_value ); ?></option>
<?php endforeach; ?>
</select>
<?php echo $this->get_description_html( $data ); ?>
</fieldset>
</td>
</tr>
<?php
return ob_get_clean();
}
/**
@ -609,21 +582,26 @@ abstract class WC_Settings_API {
* @return string
*/
public function generate_title_html( $key, $data ) {
$html = '';
$defaults = array(
'title' => '',
'class' => '',
'css' => ''
);
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data = wp_parse_args( $data, $defaults );
$html .= '</table>' . "\n";
$html .= '<h4 class="' . esc_attr( $data['class'] ) . '">' . wp_kses_post( $data['title'] ) . '</h4>' . "\n";
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= '<p>' . wp_kses_post( $data['description'] ) . '</p>' . "\n"; }
$html .= '<table class="form-table">' . "\n";
return $html;
ob_start();
?>
</table>
<h4 class="<?php echo esc_attr( $data['class'] ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></h4>
<?php if ( ! empty( $data['description'] ) ) : ?>
<p><?php echo wp_kses_post( $data['description'] ); ?></p>
<?php endif; ?>
<table class="form-table">
<?php
return ob_get_clean();
}
/**
* Validate Settings Field Data.
*
@ -632,10 +610,8 @@ abstract class WC_Settings_API {
* @since 1.0.0
* @uses method_exists()
* @param bool $form_fields (default: false)
* @return void
*/
public function validate_settings_fields( $form_fields = false ) {
if ( ! $form_fields )
$form_fields = $this->form_fields;
@ -660,15 +636,9 @@ abstract class WC_Settings_API {
$field = $this->{'validate_text_field'}( $k );
$this->sanitized_fields[ $k ] = $field;
}
// Format values
if ( isset( $v['class'] ) && strstr( $v['class'], 'wc_input_decimal' ) ) {
$this->sanitized_fields[ $k ] = ( $this->sanitized_fields[ $k ] === '' ) ? '' : woocommerce_format_decimal( $this->sanitized_fields[ $k ], false );
}
}
}
/**
* Validate Checkbox Field.
*
@ -691,23 +661,55 @@ abstract class WC_Settings_API {
/**
* Validate Text Field.
*
* Make sure the data is escaped correctly, etc.
*
* @access public
* @param mixed $key
* @since 1.0.0
* @return string
*/
public function validate_text_field( $key ) {
$text = $this->get_option( $key );
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) )
$text = wp_kses_post( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
}
return $text;
}
/**
* Validate Price Field.
*
* @param mixed $key
* @return string
*/
public function validate_price_field( $key ) {
$text = $this->get_option( $key );
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
if ( $_POST[ $this->plugin_id . $this->id . '_' . $key ] !== '' )
$text = woocommerce_format_decimal( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
else
$text = '';
}
return $text;
}
/**
* Validate Price Field.
*
* @param mixed $key
* @return string
*/
public function validate_decimal_field( $key ) {
$text = $this->get_option( $key );
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
if ( $_POST[ $this->plugin_id . $this->id . '_' . $key ] !== '' )
$text = woocommerce_format_decimal( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
else
$text = '';
}
return $text;
}
/**
* Validate Password Field.
@ -729,7 +731,6 @@ abstract class WC_Settings_API {
return $text;
}
/**
* Validate Textarea Field.
*
@ -757,7 +758,6 @@ abstract class WC_Settings_API {
return $text;
}
/**
* Validate Select Field.
*
@ -799,5 +799,4 @@ abstract class WC_Settings_API {
return $value;
}
}

View File

@ -84,7 +84,14 @@ class WC_Admin_Assets {
wp_register_script( 'chosen', $woocommerce->plugin_url() . '/assets/js/chosen/chosen.jquery' . $suffix . '.js', array('jquery'), $woocommerce->version );
// WooCommerce admin pages
// Accounting
$params = array(
'mon_decimal_point' => get_option( 'woocommerce_price_decimal_sep' )
);
wp_localize_script( 'accounting', 'accounting_params', $params );
// WooCommerce admin pages
if ( in_array( $screen->id, wc_get_screen_ids() ) ) {
wp_enqueue_script( 'woocommerce_admin' );
@ -94,11 +101,14 @@ class WC_Admin_Assets {
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
$locale = localeconv();
$locale = localeconv();
$decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
$params = array(
'i18n_decimal_input_error' => __( 'Please enter in decimal format without thousand separators and currency symbols.', 'woocommerce' ),
'locale_decimal_point' => isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.'
'i18n_decimal_error' => sprintf( __( 'Please enter in decimal (%s) format without thousand separators.', 'woocommerce' ), $decimal ),
'i18n_mon_decimal_error' => sprintf( __( 'Please enter in monitary decimal (%s) format without thousand separators and currency symbols.', 'woocommerce' ), get_option( 'woocommerce_price_decimal_sep' ) ),
'decimal_point' => $decimal,
'mon_decimal_point' => get_option( 'woocommerce_price_decimal_sep' )
);
wp_localize_script( 'woocommerce_admin', 'woocommerce_admin', $params );

View File

@ -137,7 +137,7 @@ if ( class_exists( 'WP_Importer' ) ) {
array(
'tax_rate_country' => $country,
'tax_rate_state' => $state,
'tax_rate' => number_format( $rate, 4, '.', '' ),
'tax_rate' => woocommerce_format_decimal( $rate, 4 ),
'tax_rate_name' => trim( $name ),
'tax_rate_priority' => absint( $priority ),
'tax_rate_compound' => $compound ? 1 : 0,

View File

@ -812,7 +812,7 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
if ( isset( $new_price ) && $new_price != $old_regular_price ) {
$price_changed = true;
$new_price = number_format( $new_price, absint( get_option( 'woocommerce_price_num_decimals' ) ), '.', '' );
$new_price = round( $new_price, absint( get_option( 'woocommerce_price_num_decimals' ) ) );
update_post_meta( $post_id, '_regular_price', $new_price );
$product->regular_price = $new_price;
}
@ -855,7 +855,7 @@ class WC_Admin_CPT_Product extends WC_Admin_CPT {
if ( isset( $new_price ) && $new_price != $old_sale_price ) {
$price_changed = true;
$new_price = number_format( $new_price, absint( get_option( 'woocommerce_price_num_decimals' ) ), '.', '' );
$new_price = round( $new_price, absint( get_option( 'woocommerce_price_num_decimals' ) ) );
update_post_meta( $post_id, '_sale_price', $new_price );
$product->sale_price = $new_price;
}

View File

@ -63,7 +63,7 @@ class WC_Meta_Box_Coupon_Data {
woocommerce_wp_select( array( 'id' => 'discount_type', 'label' => __( 'Discount type', 'woocommerce' ), 'options' => wc_get_coupon_types() ) );
// Amount
woocommerce_wp_text_input( array( 'id' => 'coupon_amount', 'label' => __( 'Coupon amount', 'woocommerce' ), 'placeholder' => '0.00', 'description' => __( 'Value of the coupon.', 'woocommerce' ), 'class' => 'wc_input_decimal', 'desc_tip' => true ) );
woocommerce_wp_text_input( array( 'id' => 'coupon_amount', 'label' => __( 'Coupon amount', 'woocommerce' ), 'placeholder' => wc_format_localized_price( 0 ), 'description' => __( 'Value of the coupon.', 'woocommerce' ), 'data_type' => 'price', 'desc_tip' => true ) );
// Free Shipping
woocommerce_wp_checkbox( array( 'id' => 'free_shipping', 'label' => __( 'Allow free shipping', 'woocommerce' ), 'description' => sprintf(__( 'Check this box if the coupon grants free shipping. The <a href="%s">free shipping method</a> must be enabled with the "must use coupon" setting.', 'woocommerce' ), admin_url('admin.php?page=wc-settings&tab=shipping&section=WC_Shipping_Free_Shipping')) ) );
@ -82,7 +82,7 @@ class WC_Meta_Box_Coupon_Data {
echo '<div class="options_group">';
// minimum spend
woocommerce_wp_text_input( array( 'id' => 'minimum_amount', 'label' => __( 'Minimum spend', 'woocommerce' ), 'placeholder' => __( 'No minimum', 'woocommerce' ), 'description' => __( 'This field allows you to set the minimum subtotal needed to use the coupon.', 'woocommerce' ), 'class' => 'wc_input_decimal', 'desc_tip' => true ) );
woocommerce_wp_text_input( array( 'id' => 'minimum_amount', 'label' => __( 'Minimum spend', 'woocommerce' ), 'placeholder' => __( 'No minimum', 'woocommerce' ), 'description' => __( 'This field allows you to set the minimum subtotal needed to use the coupon.', 'woocommerce' ), 'data_type' => 'price', 'desc_tip' => true ) );
// Individual use
woocommerce_wp_checkbox( array( 'id' => 'individual_use', 'label' => __( 'Individual use only', 'woocommerce' ), 'description' => __( 'Check this box if the coupon cannot be used in conjunction with other coupons.', 'woocommerce' ) ) );
@ -225,7 +225,7 @@ class WC_Meta_Box_Coupon_Data {
// Add/Replace data to array
$type = woocommerce_clean( $_POST['discount_type'] );
$amount = woocommerce_format_decimal( $_POST['coupon_amount'], false );
$amount = woocommerce_format_decimal( $_POST['coupon_amount'] );
$usage_limit = empty( $_POST['usage_limit'] ) ? '' : absint( $_POST['usage_limit'] );
$usage_limit_per_user = empty( $_POST['usage_limit_per_user'] ) ? '' : absint( $_POST['usage_limit_per_user'] );
$limit_usage_to_x_items = empty( $_POST['limit_usage_to_x_items'] ) ? '' : absint( $_POST['limit_usage_to_x_items'] );
@ -234,7 +234,7 @@ class WC_Meta_Box_Coupon_Data {
$apply_before_tax = isset( $_POST['apply_before_tax'] ) ? 'yes' : 'no';
$free_shipping = isset( $_POST['free_shipping'] ) ? 'yes' : 'no';
$exclude_sale_items = isset( $_POST['exclude_sale_items'] ) ? 'yes' : 'no';
$minimum_amount = woocommerce_format_decimal( $_POST['minimum_amount'], false );
$minimum_amount = woocommerce_format_decimal( $_POST['minimum_amount'] );
$customer_email = array_filter( array_map( 'trim', explode( ',', woocommerce_clean( $_POST['customer_email'] ) ) ) );
if ( isset( $_POST['product_ids'] ) ) {

View File

@ -138,27 +138,27 @@ class WC_Meta_Box_Order_Items {
woocommerce_update_order_item_meta( $item_id, '_tax_class', woocommerce_clean( $order_item_tax_class[ $item_id ] ) );
if ( isset( $line_subtotal[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_subtotal', woocommerce_format_decimal( $line_subtotal[ $item_id ], false ) );
woocommerce_update_order_item_meta( $item_id, '_line_subtotal', woocommerce_format_decimal( $line_subtotal[ $item_id ] ) );
$subtotal += woocommerce_clean( $line_subtotal[ $item_id ] );
$subtotal += woocommerce_format_decimal( $line_subtotal[ $item_id ] );
}
if ( isset( $line_subtotal_tax[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $line_subtotal_tax[ $item_id ], false ) );
woocommerce_update_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $line_subtotal_tax[ $item_id ] ) );
$subtotal += woocommerce_clean( $line_subtotal_tax[ $item_id ] );
$subtotal += woocommerce_format_decimal( $line_subtotal_tax[ $item_id ] );
}
if ( isset( $line_total[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $line_total[ $item_id ], false ) );
woocommerce_update_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $line_total[ $item_id ] ) );
$total += woocommerce_clean( $line_total[ $item_id ] );
$total += woocommerce_format_decimal( $line_total[ $item_id ] );
}
if ( isset( $line_tax[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $line_tax[ $item_id ], false ) );
woocommerce_update_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $line_tax[ $item_id ] ) );
$total += woocommerce_clean( $line_tax[ $item_id ] );
$total += woocommerce_format_decimal( $line_tax[ $item_id ] );
}
// Clear meta cache
@ -186,6 +186,6 @@ class WC_Meta_Box_Order_Items {
}
// Update cart discount from item totals
update_post_meta( $post_id, '_cart_discount', woocommerce_format_decimal( $subtotal - $total, false ) );
update_post_meta( $post_id, '_cart_discount', $subtotal - $total );
}
}

View File

@ -111,16 +111,16 @@ class WC_Meta_Box_Order_Totals {
<div class="totals_group">
<h4><label for="_order_total"><?php _e( 'Order Discount', 'woocommerce' ); ?></label></h4>
<input type="text" class="wc_input_decimal" id="_order_discount" name="_order_discount" placeholder="0.00" value="<?php
<input type="text" class="wc_input_price" id="_order_discount" name="_order_discount" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php
if ( isset( $data['_order_discount'][0] ) )
echo esc_attr( $data['_order_discount'][0] );
echo esc_attr( wc_format_localized_price( $data['_order_discount'][0] ) );
?>" />
</div>
<div class="totals_group">
<h4><label for="_order_total"><?php _e( 'Order Total', 'woocommerce' ); ?></label></h4>
<input type="text" class="wc_input_decimal" id="_order_total" name="_order_total" placeholder="0.00" value="<?php
<input type="text" class="wc_input_price" id="_order_total" name="_order_total" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php
if ( isset( $data['_order_total'][0] ) )
echo esc_attr( $data['_order_total'][0] );
echo esc_attr( wc_format_localized_price( $data['_order_total'][0] ) );
?>" />
</div>
<?php
@ -206,15 +206,15 @@ class WC_Meta_Box_Order_Totals {
woocommerce_update_order_item_meta( $new_id, 'compound', $compound );
if ( isset( $order_taxes_amount[ $item_id ][ $new_key ] ) ) {
woocommerce_update_order_item_meta( $new_id, 'tax_amount', woocommerce_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ], false ) );
woocommerce_update_order_item_meta( $new_id, 'tax_amount', woocommerce_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ] ) );
$total_tax += woocommerce_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ], false );
$total_tax += woocommerce_format_decimal( $order_taxes_amount[ $item_id ][ $new_key ] );
}
if ( isset( $order_taxes_shipping_amount[ $item_id ][ $new_key ] ) ) {
woocommerce_update_order_item_meta( $new_id, 'shipping_tax_amount', woocommerce_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ], false ) );
woocommerce_update_order_item_meta( $new_id, 'shipping_tax_amount', woocommerce_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ] ) );
$total_shipping_tax += woocommerce_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ], false );
$total_shipping_tax += woocommerce_format_decimal( $order_taxes_shipping_amount[ $item_id ][ $new_key ] );
}
}
}
@ -254,25 +254,25 @@ class WC_Meta_Box_Order_Totals {
woocommerce_update_order_item_meta( $item_id, 'compound', $compound );
if ( isset( $order_taxes_amount[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, 'tax_amount', woocommerce_format_decimal( $order_taxes_amount[ $item_id ], false ) );
woocommerce_update_order_item_meta( $item_id, 'tax_amount', woocommerce_format_decimal( $order_taxes_amount[ $item_id ] ) );
$total_tax += woocommerce_format_decimal( $order_taxes_amount[ $item_id ], false );
$total_tax += woocommerce_format_decimal( $order_taxes_amount[ $item_id ] );
}
if ( isset( $order_taxes_shipping_amount[ $item_id ] ) ) {
woocommerce_update_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_format_decimal( $order_taxes_shipping_amount[ $item_id ], false ) );
woocommerce_update_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_format_decimal( $order_taxes_shipping_amount[ $item_id ] ) );
$total_shipping_tax += woocommerce_format_decimal( $order_taxes_shipping_amount[ $item_id ], false );
$total_shipping_tax += woocommerce_format_decimal( $order_taxes_shipping_amount[ $item_id ] );
}
}
}
}
// Update totals
update_post_meta( $post_id, '_order_tax', woocommerce_format_decimal( woocommerce_round_tax_total( $total_tax ), false ) );
update_post_meta( $post_id, '_order_shipping_tax', woocommerce_format_decimal( woocommerce_round_tax_total( $total_shipping_tax ), false ) );
update_post_meta( $post_id, '_order_discount', woocommerce_format_decimal( $_POST['_order_discount'], false ) );
update_post_meta( $post_id, '_order_total', woocommerce_format_decimal( $_POST['_order_total'], false ) );
update_post_meta( $post_id, '_order_tax', woocommerce_round_tax_total( $total_tax ) );
update_post_meta( $post_id, '_order_shipping_tax', woocommerce_round_tax_total( $total_shipping_tax ) );
update_post_meta( $post_id, '_order_discount', woocommerce_format_decimal( $_POST['_order_discount'] ) );
update_post_meta( $post_id, '_order_total', woocommerce_format_decimal( $_POST['_order_total'] ) );
// Shipping Rows
$order_shipping = 0;
@ -291,7 +291,7 @@ class WC_Meta_Box_Order_Totals {
foreach ( $value as $new_key => $new_value ) {
$method_id = woocommerce_clean( $shipping_method[ $item_id ][ $new_key ] );
$method_title = woocommerce_clean( $shipping_method_title[ $item_id ][ $new_key ] );
$cost = woocommerce_format_decimal( $shipping_cost[ $item_id ][ $new_key ], false );
$cost = woocommerce_format_decimal( $shipping_cost[ $item_id ][ $new_key ] );
$new_id = woocommerce_add_order_item( $post_id, array(
'order_item_name' => $method_title,
@ -311,7 +311,7 @@ class WC_Meta_Box_Order_Totals {
$item_id = absint( $item_id );
$method_id = woocommerce_clean( $shipping_method[ $item_id ] );
$method_title = woocommerce_clean( $shipping_method_title[ $item_id ] );
$cost = woocommerce_format_decimal( $shipping_cost[ $item_id ], false );
$cost = woocommerce_format_decimal( $shipping_cost[ $item_id ] );
$wpdb->update(
$wpdb->prefix . "woocommerce_order_items",
@ -339,6 +339,6 @@ class WC_Meta_Box_Order_Totals {
delete_post_meta( $post_id, '_shipping_method' );
delete_post_meta( $post_id, '_shipping_method_title' );
update_post_meta( $post_id, '_order_shipping', woocommerce_format_decimal( $order_shipping, false ) );
update_post_meta( $post_id, '_order_shipping', $order_shipping );
}
}

View File

@ -153,10 +153,10 @@ class WC_Meta_Box_Product_Data {
echo '<div class="options_group pricing show_if_simple show_if_external">';
// Price
woocommerce_wp_text_input( array( 'id' => '_regular_price', 'class' => 'wc_input_decimal short', 'label' => __( 'Regular Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')' ) );
woocommerce_wp_text_input( array( 'id' => '_regular_price', 'label' => __( 'Regular Price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')', 'data_type' => 'price' ) );
// Special Price
woocommerce_wp_text_input( array( 'id' => '_sale_price', 'class' => 'wc_input_decimal short', 'label' => __( 'Sale Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')', 'description' => '<a href="#" class="sale_schedule">' . __( 'Schedule', 'woocommerce' ) . '</a>' ) );
woocommerce_wp_text_input( array( 'id' => '_sale_price', 'data_type' => 'price', 'label' => __( 'Sale Price', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')', 'description' => '<a href="#" class="sale_schedule">' . __( 'Schedule', 'woocommerce' ) . '</a>' ) );
// Special Price date range
$sale_price_dates_from = ( $date = get_post_meta( $thepostid, '_sale_price_dates_from', true ) ) ? date_i18n( 'Y-m-d', $date ) : '';
@ -340,16 +340,16 @@ class WC_Meta_Box_Product_Data {
// Weight
if ( wc_product_weight_enabled() )
woocommerce_wp_text_input( array( 'id' => '_weight', 'label' => __( 'Weight', 'woocommerce' ) . ' ('.get_option('woocommerce_weight_unit').')', 'placeholder' => '0.00', 'description' => __( 'Weight in decimal form', 'woocommerce' ), 'type' => 'text', 'class' => 'wc_input_decimal short' ) );
woocommerce_wp_text_input( array( 'id' => '_weight', 'label' => __( 'Weight', 'woocommerce' ) . ' (' . get_option('woocommerce_weight_unit') . ')', 'placeholder' => wc_format_localized_decimal( 0 ), 'description' => __( 'Weight in decimal form', 'woocommerce' ), 'type' => 'text', 'data_type' => 'decimal' ) );
// Size fields
if ( wc_product_dimensions_enabled() ) {
?><p class="form-field dimensions_field">
<label for="product_length"><?php echo __( 'Dimensions', 'woocommerce' ) . ' (' . get_option( 'woocommerce_dimension_unit' ) . ')'; ?></label>
<span class="wrap">
<input id="product_length" placeholder="<?php _e( 'Length', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="_length" value="<?php echo esc_attr( get_post_meta( $thepostid, '_length', true ) ); ?>" />
<input placeholder="<?php _e( 'Width', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="_width" value="<?php echo esc_attr( get_post_meta( $thepostid, '_width', true ) ); ?>" />
<input placeholder="<?php _e( 'Height', 'woocommerce' ); ?>" class="input-text wc_input_decimal last" size="6" type="text" name="_height" value="<?php echo esc_attr( get_post_meta( $thepostid, '_height', true ) ); ?>" />
<input id="product_length" placeholder="<?php _e( 'Length', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="_length" value="<?php echo esc_attr( wc_format_localized_decimal( get_post_meta( $thepostid, '_length', true ) ) ); ?>" />
<input placeholder="<?php _e( 'Width', 'woocommerce' ); ?>" class="input-text wc_input_decimal" size="6" type="text" name="_width" value="<?php echo esc_attr( wc_format_localized_decimal( get_post_meta( $thepostid, '_width', true ) ) ); ?>" />
<input placeholder="<?php _e( 'Height', 'woocommerce' ); ?>" class="input-text wc_input_decimal last" size="6" type="text" name="_height" value="<?php echo esc_attr( wc_format_localized_decimal( get_post_meta( $thepostid, '_height', true ) ) ); ?>" />
</span>
<span class="description"><?php _e( 'LxWxH in decimal form', 'woocommerce' ); ?></span>
</p><?php
@ -783,24 +783,24 @@ class WC_Meta_Box_Product_Data {
'attributes' => $attributes,
'tax_class_options' => $tax_class_options,
'sku' => get_post_meta( $post->ID, '_sku', true ),
'weight' => get_post_meta( $post->ID, '_weight', true ),
'length' => get_post_meta( $post->ID, '_length', true ),
'width' => get_post_meta( $post->ID, '_width', true ),
'height' => get_post_meta( $post->ID, '_height', true ),
'weight' => wc_format_localized_decimal( get_post_meta( $post->ID, '_weight', true ) ),
'length' => wc_format_localized_decimal( get_post_meta( $post->ID, '_length', true ) ),
'width' => wc_format_localized_decimal( get_post_meta( $post->ID, '_width', true ) ),
'height' => wc_format_localized_decimal( get_post_meta( $post->ID, '_height', true ) ),
'tax_class' => get_post_meta( $post->ID, '_tax_class', true )
);
if ( ! $parent_data['weight'] )
$parent_data['weight'] = '0.00';
$parent_data['weight'] = wc_format_localized_decimal( 0 );
if ( ! $parent_data['length'] )
$parent_data['length'] = '0';
$parent_data['length'] = wc_format_localized_decimal( 0 );
if ( ! $parent_data['width'] )
$parent_data['width'] = '0';
$parent_data['width'] = wc_format_localized_decimal( 0 );
if ( ! $parent_data['height'] )
$parent_data['height'] = '0';
$parent_data['height'] = wc_format_localized_decimal( 0 );
// Get variations
$args = array(
@ -827,7 +827,6 @@ class WC_Meta_Box_Product_Data {
$variation_fields = array(
'_sku',
'_stock',
'_price',
'_regular_price',
'_sale_price',
'_weight',
@ -847,18 +846,17 @@ class WC_Meta_Box_Product_Data {
foreach ( $variation_fields as $field )
$$field = isset( $variation_data[ $field ][0] ) ? maybe_unserialize( $variation_data[ $field ][0] ) : '';
// Tax class handling
$_tax_class = isset( $variation_data['_tax_class'][0] ) ? $variation_data['_tax_class'][0] : null;
// Price backwards compat
if ( $_regular_price == '' && $_price )
$_regular_price = $_price;
// Get image
$image = '';
$image_id = absint( $_thumbnail_id );
if ( $image_id )
$image = wp_get_attachment_thumb_url( $image_id );
$image_id = absint( $_thumbnail_id );
$image = $image_id ? wp_get_attachment_thumb_url( $image_id ) : '';
// Locale formatting
$_regular_price = wc_format_localized_price( $_regular_price );
$_sale_price = wc_format_localized_price( $_sale_price );
$_weight = wc_format_localized_decimal( $_weight );
$_length = wc_format_localized_decimal( $_length );
$_width = wc_format_localized_decimal( $_width );
$_height = wc_format_localized_decimal( $_height );
include( 'views/html-variation-admin.php' );
@ -936,9 +934,9 @@ class WC_Meta_Box_Product_Data {
// Update post meta
if ( isset( $_POST['_regular_price'] ) )
update_post_meta( $post_id, '_regular_price', ( $_POST['_regular_price'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_regular_price'], false ) );
update_post_meta( $post_id, '_regular_price', ( $_POST['_regular_price'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_regular_price'] ) );
if ( isset( $_POST['_sale_price'] ) )
update_post_meta( $post_id, '_sale_price', ( $_POST['_sale_price'] === '' ? '' : woocommerce_format_decimal( $_POST['_sale_price'], false ) ) );
update_post_meta( $post_id, '_sale_price', ( $_POST['_sale_price'] === '' ? '' : woocommerce_format_decimal( $_POST['_sale_price'] ) ) );
if ( isset( $_POST['_tax_status'] ) ) update_post_meta( $post_id, '_tax_status', stripslashes( $_POST['_tax_status'] ) );
if ( isset( $_POST['_tax_class'] ) ) update_post_meta( $post_id, '_tax_class', stripslashes( $_POST['_tax_class'] ) );
if ( isset( $_POST['_visibility'] ) ) update_post_meta( $post_id, '_visibility', stripslashes( $_POST['_visibility'] ) );
@ -949,16 +947,16 @@ class WC_Meta_Box_Product_Data {
if ( $is_virtual == 'no' ) {
if ( isset( $_POST['_weight'] ) )
update_post_meta( $post_id, '_weight', ( $_POST['_weight'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_weight'], false ) );
update_post_meta( $post_id, '_weight', ( $_POST['_weight'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_weight'] ) );
if ( isset( $_POST['_length'] ) )
update_post_meta( $post_id, '_length', ( $_POST['_length'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_length'], false ) );
update_post_meta( $post_id, '_length', ( $_POST['_length'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_length'] ) );
if ( isset( $_POST['_width'] ) )
update_post_meta( $post_id, '_width', ( $_POST['_width'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_width'], false ) );
update_post_meta( $post_id, '_width', ( $_POST['_width'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_width'] ) );
if ( isset( $_POST['_height'] ) )
update_post_meta( $post_id, '_height', ( $_POST['_height'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_height'], false ) );
update_post_meta( $post_id, '_height', ( $_POST['_height'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_height'] ) );
} else {
update_post_meta( $post_id, '_weight', '' );
@ -1122,17 +1120,17 @@ class WC_Meta_Box_Product_Data {
// Update price if on sale
if ( $_POST['_sale_price'] !== '' && $date_to == '' && $date_from == '' )
update_post_meta( $post_id, '_price', woocommerce_format_decimal( $_POST['_sale_price'], false ) );
update_post_meta( $post_id, '_price', woocommerce_format_decimal( $_POST['_sale_price'] ) );
else
update_post_meta( $post_id, '_price', ( $_POST['_regular_price'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_regular_price'], false ) );
update_post_meta( $post_id, '_price', ( $_POST['_regular_price'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_regular_price'] ) );
if ( $_POST['_sale_price'] !== '' && $date_from && strtotime( $date_from ) < strtotime( 'NOW', current_time( 'timestamp' ) ) )
update_post_meta( $post_id, '_price', woocommerce_format_decimal( $_POST['_sale_price'], false ) );
update_post_meta( $post_id, '_price', woocommerce_format_decimal( $_POST['_sale_price'] ) );
if ( $date_to && strtotime( $date_to ) < strtotime( 'NOW', current_time( 'timestamp' ) ) ) {
update_post_meta( $post_id, '_price', ( $_POST['_regular_price'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_regular_price'], false ) );
update_post_meta( $post_id, '_sale_price_dates_from', '');
update_post_meta( $post_id, '_sale_price_dates_to', '');
update_post_meta( $post_id, '_price', ( $_POST['_regular_price'] === '' ) ? '' : woocommerce_format_decimal( $_POST['_regular_price'] ) );
update_post_meta( $post_id, '_sale_price_dates_from', '' );
update_post_meta( $post_id, '_sale_price_dates_to', '' );
}
}
@ -1392,21 +1390,21 @@ class WC_Meta_Box_Product_Data {
update_post_meta( $variation_id, '_downloadable', woocommerce_clean( $is_downloadable ) );
if ( isset( $variable_weight[ $i ] ) )
update_post_meta( $variation_id, '_weight', ( $variable_weight[ $i ] === '' ) ? '' : woocommerce_format_decimal( $variable_weight[ $i ], false ) );
update_post_meta( $variation_id, '_weight', ( $variable_weight[ $i ] === '' ) ? '' : woocommerce_format_decimal( $variable_weight[ $i ] ) );
if ( isset( $variable_length[ $i ] ) )
update_post_meta( $variation_id, '_length', ( $variable_length[ $i ] === '' ) ? '' : woocommerce_format_decimal( $variable_length[ $i ], false ) );
update_post_meta( $variation_id, '_length', ( $variable_length[ $i ] === '' ) ? '' : woocommerce_format_decimal( $variable_length[ $i ] ) );
if ( isset( $variable_width[ $i ] ) )
update_post_meta( $variation_id, '_width', ( $variable_width[ $i ] === '' ) ? '' : woocommerce_format_decimal( $variable_width[ $i ], false ) );
update_post_meta( $variation_id, '_width', ( $variable_width[ $i ] === '' ) ? '' : woocommerce_format_decimal( $variable_width[ $i ] ) );
if ( isset( $variable_height[ $i ] ) )
update_post_meta( $variation_id, '_height', ( $variable_height[ $i ] === '' ) ? '' : woocommerce_format_decimal( $variable_height[ $i ], false ) );
update_post_meta( $variation_id, '_height', ( $variable_height[ $i ] === '' ) ? '' : woocommerce_format_decimal( $variable_height[ $i ] ) );
// Stock handling
if ( isset($variable_stock[$i]) )
wc_update_product_stock( $variation_id, woocommerce_clean( $variable_stock[ $i ] ) );
// Price handling
$regular_price = woocommerce_format_decimal( $variable_regular_price[ $i ], false );
$sale_price = ( $variable_sale_price[ $i ] === '' ? '' : woocommerce_format_decimal( $variable_sale_price[ $i ], false ) );
$regular_price = woocommerce_format_decimal( $variable_regular_price[ $i ] );
$sale_price = ( $variable_sale_price[ $i ] === '' ? '' : woocommerce_format_decimal( $variable_sale_price[ $i ] ) );
$date_from = woocommerce_clean( $variable_sale_price_dates_from[ $i ] );
$date_to = woocommerce_clean( $variable_sale_price_dates_to[ $i ] );

View File

@ -59,7 +59,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<?php if ( isset( $item['line_total'] ) ) echo woocommerce_price( woocommerce_round_tax_total( $item['line_tax'] ) ); ?>
</div>
<div class="edit" style="display:none">
<label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_total'] ) ) echo esc_attr( $item['line_total'] ); ?>" class="line_total wc_input_decimal" /></label>
<label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['line_total'] ) ) echo esc_attr( wc_format_localized_price( $item['line_total'] ) ); ?>" class="line_total wc_input_price" /></label>
</div>
</td>
@ -70,7 +70,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<?php if ( isset( $item['line_tax'] ) ) echo woocommerce_price( woocommerce_round_tax_total( $item['line_tax'] ) ); ?>
</div>
<div class="edit" style="display:none">
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_tax'] ) ) echo esc_attr( $item['line_tax'] ); ?>" class="line_tax wc_input_decimal" />
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['line_tax'] ) ) echo esc_attr( wc_format_localized_price( $item['line_tax'] ) ); ?>" class="line_tax wc_input_price" />
</div>
</td>

View File

@ -166,9 +166,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?>
</div>
<div class="edit" style="display:none">
<span class="subtotal"><label><?php _e( 'Subtotal', 'woocommerce' ); ?>: <a class="tips" data-tip="<?php _e( 'Before pre-tax discounts.', 'woocommerce' ); ?>" href="#">[?]</a> <input type="text" name="line_subtotal[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_subtotal'] ) ) echo esc_attr( $item['line_subtotal'] ); ?>" class="line_subtotal wc_input_decimal" /></label></span>
<span class="subtotal"><label><?php _e( 'Subtotal', 'woocommerce' ); ?>: <a class="tips" data-tip="<?php _e( 'Before pre-tax discounts.', 'woocommerce' ); ?>" href="#">[?]</a> <input type="text" name="line_subtotal[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['line_subtotal'] ) ) echo esc_attr( wc_format_localized_price( $item['line_subtotal'] ) ); ?>" class="line_subtotal wc_input_price" /></label></span>
<label><?php _e( 'Total', 'woocommerce' ); ?>: <a class="tips" data-tip="<?php _e( 'After pre-tax discounts.', 'woocommerce' ); ?>" href="#">[?]</a> <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_total'] ) ) echo esc_attr( $item['line_total'] ); ?>" class="line_total wc_input_decimal" /></label>
<label><?php _e( 'Total', 'woocommerce' ); ?>: <a class="tips" data-tip="<?php _e( 'After pre-tax discounts.', 'woocommerce' ); ?>" href="#">[?]</a> <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['line_total'] ) ) echo esc_attr( wc_format_localized_price( $item['line_total'] ) ); ?>" class="line_total wc_input_price" /></label>
</div>
</td>
@ -185,9 +185,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
?>
</div>
<div class="edit" style="display:none">
<span class="subtotal"><input type="text" name="line_subtotal_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_subtotal_tax'] ) ) echo esc_attr( $item['line_subtotal_tax'] ); ?>" class="line_subtotal_tax wc_input_decimal" /></span>
<span class="subtotal"><input type="text" name="line_subtotal_tax[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['line_subtotal_tax'] ) ) echo esc_attr( wc_format_localized_price( $item['line_subtotal_tax'] ) ); ?>" class="line_subtotal_tax wc_input_price" /></span>
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_tax'] ) ) echo esc_attr( $item['line_tax'] ); ?>" class="line_tax wc_input_decimal" />
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['line_tax'] ) ) echo esc_attr( wc_format_localized_price( $item['line_tax'] ) ); ?>" class="line_tax wc_input_price" />
</div>
</td>

View File

@ -36,7 +36,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
</select>
</p>
<p class="last">
<input type="text" class="shipping_cost wc_input_decimal" name="shipping_cost[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php _e( '0.00', 'woocommerce' ); ?>" value="<?php echo esc_attr( $shipping_cost ); ?>" />
<input type="text" class="shipping_cost wc_input_price" name="shipping_cost[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $shipping_cost ) ); ?>" />
</p>
<a href="#" class="delete_total_row">&times;</a>
<div class="clear"></div>

View File

@ -15,11 +15,11 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
</p>
<p class="first">
<label><?php _e( 'Sales Tax', 'woocommerce' ) ?></label>
<input type="text" class="order_taxes_amount wc_input_decimal" name="order_taxes_amount[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="0.00" value="<?php if ( isset( $item['tax_amount'] ) ) echo esc_attr( $item['tax_amount'] ); ?>" />
<input type="text" class="order_taxes_amount wc_input_price" name="order_taxes_amount[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['tax_amount'] ) ) echo esc_attr( wc_format_localized_price( $item['tax_amount'] ) ); ?>" />
</p>
<p class="last">
<label><?php _e( 'Shipping Tax', 'woocommerce' ) ?></label>
<input type="text" class="order_taxes_shipping_amount wc_input_decimal" name="order_taxes_shipping_amount[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="0.00" value="<?php if ( isset( $item['shipping_tax_amount'] ) ) echo esc_attr( $item['shipping_tax_amount'] ); ?>" />
<input type="text" class="order_taxes_shipping_amount wc_input_price" name="order_taxes_shipping_amount[<?php echo $item_id ? $item_id : 'new][]'; ?>]" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" value="<?php if ( isset( $item['shipping_tax_amount'] ) ) echo esc_attr( wc_format_localized_price( $item['shipping_tax_amount'] ) ); ?>" />
</p>
<a href="#" class="delete_total_row">&times;</a>
<div class="clear"></div>

View File

@ -70,11 +70,11 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
<tr class="variable_pricing">
<td>
<label><?php echo __( 'Regular Price:', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')'; ?></label>
<input type="text" size="5" name="variable_regular_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_regular_price ) ) echo esc_attr( $_regular_price ); ?>" class="wc_input_decimal" placeholder="<?php _e( 'Variation price (required)', 'woocommerce' ); ?>" />
<input type="text" size="5" name="variable_regular_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_regular_price ) ) echo esc_attr( $_regular_price ); ?>" class="wc_input_price" placeholder="<?php _e( 'Variation price (required)', 'woocommerce' ); ?>" />
</td>
<td>
<label><?php echo __( 'Sale Price:', 'woocommerce' ) . ' ('.get_woocommerce_currency_symbol().')'; ?> <a href="#" class="sale_schedule"><?php _e( 'Schedule', 'woocommerce' ); ?></a><a href="#" class="cancel_sale_schedule" style="display:none"><?php _e( 'Cancel schedule', 'woocommerce' ); ?></a></label>
<input type="text" size="5" name="variable_sale_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_sale_price ) ) echo esc_attr( $_sale_price ); ?>" class="wc_input_decimal" />
<input type="text" size="5" name="variable_sale_price[<?php echo $loop; ?>]" value="<?php if ( isset( $_sale_price ) ) echo esc_attr( $_sale_price ); ?>" class="wc_input_price" />
</td>
</tr>

View File

@ -20,13 +20,25 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function woocommerce_wp_text_input( $field ) {
global $thepostid, $post, $woocommerce;
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
$field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : '';
$field['class'] = isset( $field['class'] ) ? $field['class'] : 'short';
$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
$field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true );
$field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
$field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
$data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
switch ( $data_type ) {
case 'price' :
$field['class'] .= ' wc_input_price';
$field['value'] = wc_format_localized_price( $field['value'] );
break;
case 'decimal' :
$field['class'] .= ' wc_input_decimal';
$field['value'] = wc_format_localized_decimal( $field['value'] );
break;
}
// Custom attribute handling
$custom_attributes = array();

View File

@ -1153,7 +1153,7 @@ class WC_Cart {
do_action( 'woocommerce_calculate_totals', $this );
// Grand Total - Discounted product prices, discounted tax, shipping cost + tax, and any discounts to be added after tax (e.g. store credit)
$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', number_format( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total - $this->discount_total + $this->fee_total, $this->dp, '.', '' ), $this ) );
$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', round( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total - $this->discount_total + $this->fee_total, $this->dp ), $this ) );
} else {
@ -1648,7 +1648,7 @@ class WC_Cart {
* @access public
*/
public function apply_cart_discounts_after_tax() {
$pre_discount_total = number_format( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total + $this->fee_total, $this->dp, '.', '' );
$pre_discount_total = round( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total + $this->fee_total, $this->dp );
if ( $this->applied_coupons ) {
foreach ( $this->applied_coupons as $code ) {

View File

@ -269,10 +269,10 @@ class WC_Checkout {
woocommerce_add_order_item_meta( $item_id, '_tax_class', $_product->get_tax_class() );
woocommerce_add_order_item_meta( $item_id, '_product_id', $values['product_id'] );
woocommerce_add_order_item_meta( $item_id, '_variation_id', $values['variation_id'] );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal', woocommerce_format_decimal( $values['line_subtotal'], false ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'], false ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $values['line_tax'], false ) );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $values['line_subtotal_tax'], false ) );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal', woocommerce_format_decimal( $values['line_subtotal'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $values['line_tax'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $values['line_subtotal_tax'] ) );
// Store variation data in meta so admin can view it
if ( $values['variation'] && is_array( $values['variation'] ) )
@ -300,8 +300,8 @@ class WC_Checkout {
else
woocommerce_add_order_item_meta( $item_id, '_tax_class', '0' );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $fee->amount, false ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $fee->tax, false ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $fee->amount ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $fee->tax ) );
}
// Store shipping for all packages
@ -319,7 +319,7 @@ class WC_Checkout {
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'method_id', $method->id );
woocommerce_add_order_item_meta( $item_id, 'cost', woocommerce_format_decimal( $method->cost, false ) );
woocommerce_add_order_item_meta( $item_id, 'cost', woocommerce_format_decimal( $method->cost ) );
}
}
}
@ -337,8 +337,8 @@ class WC_Checkout {
woocommerce_add_order_item_meta( $item_id, 'rate_id', $key );
woocommerce_add_order_item_meta( $item_id, 'label', WC()->cart->tax->get_rate_label( $key ) );
woocommerce_add_order_item_meta( $item_id, 'compound', absint( WC()->cart->tax->is_compound( $key ) ? 1 : 0 ) );
woocommerce_add_order_item_meta( $item_id, 'tax_amount', woocommerce_format_decimal( isset( WC()->cart->taxes[ $key ] ) ? WC()->cart->taxes[ $key ] : 0, false ) );
woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_format_decimal( isset( WC()->cart->shipping_taxes[ $key ] ) ? WC()->cart->shipping_taxes[ $key ] : 0, false ) );
woocommerce_add_order_item_meta( $item_id, 'tax_amount', woocommerce_format_decimal( isset( WC()->cart->taxes[ $key ] ) ? WC()->cart->taxes[ $key ] : 0 ) );
woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_format_decimal( isset( WC()->cart->shipping_taxes[ $key ] ) ? WC()->cart->shipping_taxes[ $key ] : 0 ) );
}
}
@ -362,12 +362,12 @@ class WC_Checkout {
update_post_meta( $order_id, '_payment_method', $this->payment_method->id );
update_post_meta( $order_id, '_payment_method_title', $this->payment_method->get_title() );
}
update_post_meta( $order_id, '_order_shipping', woocommerce_format_decimal( WC()->cart->shipping_total, false ) );
update_post_meta( $order_id, '_order_discount', woocommerce_format_decimal( WC()->cart->get_order_discount_total(), false ) );
update_post_meta( $order_id, '_cart_discount', woocommerce_format_decimal( WC()->cart->get_cart_discount_total(), false ) );
update_post_meta( $order_id, '_order_tax', woocommerce_format_decimal( woocommerce_round_tax_total( WC()->cart->tax_total ), false ) );
update_post_meta( $order_id, '_order_shipping_tax', woocommerce_format_decimal( woocommerce_round_tax_total( WC()->cart->shipping_tax_total ), false ) );
update_post_meta( $order_id, '_order_total', woocommerce_format_decimal( WC()->cart->total ) );
update_post_meta( $order_id, '_order_shipping', woocommerce_format_decimal( WC()->cart->shipping_total ) );
update_post_meta( $order_id, '_order_discount', woocommerce_format_decimal( WC()->cart->get_order_discount_total() ) );
update_post_meta( $order_id, '_cart_discount', woocommerce_format_decimal( WC()->cart->get_cart_discount_total() ) );
update_post_meta( $order_id, '_order_tax', woocommerce_format_decimal( woocommerce_round_tax_total( WC()->cart->tax_total ) ) );
update_post_meta( $order_id, '_order_shipping_tax', woocommerce_format_decimal( woocommerce_round_tax_total( WC()->cart->shipping_tax_total ) ) );
update_post_meta( $order_id, '_order_total', woocommerce_format_decimal( WC()->cart->total, get_option( 'woocommerce_price_num_decimals' ) ) );
update_post_meta( $order_id, '_order_key', apply_filters('woocommerce_generate_order_key', uniqid('order_') ) );
update_post_meta( $order_id, '_customer_user', absint( $this->customer_id ) );

View File

@ -512,7 +512,7 @@ class WC_Order {
else
$price = ( $item['line_subtotal'] / $item['qty'] );
$price = $round ? number_format( $price, 2, '.', '' ) : $price;
$price = $round ? round( $price, 2 ) : $price;
return apply_filters( 'woocommerce_order_amount_item_subtotal', $price, $this );
}
@ -532,7 +532,7 @@ class WC_Order {
else
$price = $item['line_subtotal'];
$price = $round ? number_format( $price, 2, '.', '' ) : $price;
$price = $round ? round( $price, 2 ) : $price;
return apply_filters( 'woocommerce_order_amount_line_subtotal', $price, $this );
}
@ -552,7 +552,7 @@ class WC_Order {
else
$price = $item['line_total'] / $item['qty'];
$price = $round ? number_format( $price, 2, '.', '' ) : $price;
$price = $round ? round( $price, 2 ) : $price;
return apply_filters( 'woocommerce_order_amount_item_total', $price, $this );
}
@ -566,7 +566,7 @@ class WC_Order {
* @return float
*/
public function get_line_total( $item, $inc_tax = false ) {
$line_total = $inc_tax ? number_format( $item['line_total'] + $item['line_tax'] , 2, '.', '' ) : number_format( $item['line_total'] , 2, '.', '' );
$line_total = $inc_tax ? round( $item['line_total'] + $item['line_tax'], 2 ) : round( $item['line_total'], 2 );
return apply_filters( 'woocommerce_order_amount_line_total', $line_total, $this );
}

View File

@ -19,9 +19,35 @@ class WC_Post_Data {
* Constructor
*/
public function __construct() {
add_filter( 'update_order_item_metadata', array( $this, 'update_order_item_metadata' ), 10, 5 );
add_filter( 'update_post_metadata', array( $this, 'update_post_metadata' ), 10, 5 );
}
/**
* Ensure floats are correctly converted to strings based on PHP locale
*
* @param null $check
* @param int $object_id
* @param string $meta_key
* @param mixed $meta_value
* @param mixed $prev_value
* @return null|bool
*/
public function update_order_item_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) {
if ( ! empty( $meta_value ) && is_float( $meta_value ) ) {
// Convert float to string
$meta_value = wc_float_to_string( $meta_value );
// Update meta value with new string
update_metadata( 'order_item', $object_id, $meta_key, $meta_value, $prev_value );
// Return
return true;
}
return $check;
}
/**
* Ensure floats are correctly converted to strings based on PHP locale
*
@ -36,7 +62,7 @@ class WC_Post_Data {
if ( ! empty( $meta_value ) && is_float( $meta_value ) && in_array( get_post_type( $object_id ), array( 'shop_order', 'shop_coupon', 'product', 'product_variation' ) ) ) {
// Convert float to string
$meta_value = wc_parse_float( $meta_value );
$meta_value = wc_float_to_string( $meta_value );
// Update meta value with new string
update_metadata( 'post', $object_id, $meta_key, $meta_value, $prev_value );
@ -44,7 +70,6 @@ class WC_Post_Data {
// Return
return true;
}
return $check;
}

View File

@ -347,7 +347,6 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
// No longer using shipping_1 because
// a) paypal ignore it if *any* shipping rules are within paypal
// b) paypal ignore anything over 5 digits, so 999.99 is the max
// $paypal_args['shipping_1'] = number_format( $order->get_total_shipping() + $order->get_shipping_tax() , 2, '.', '' );
if ( ( $order->get_total_shipping() + $order->get_shipping_tax() ) > 0 ) {
$paypal_args['item_name_2'] = __( 'Shipping via', 'woocommerce' ) . ' ' . ucwords( $order->get_shipping_method() );
$paypal_args['quantity_2'] = '1';

View File

@ -117,12 +117,11 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
),
'cost_per_order' => array(
'title' => __( 'Cost per order', 'woocommerce' ),
'type' => 'text',
'class' => 'wc_input_decimal',
'type' => 'price',
'placeholder' => wc_format_localized_price( 0 ),
'description' => __( 'Enter a cost (excluding tax) per order, e.g. 5.00. Leave blank to disable.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
'placeholder' => '0.00',
'desc_tip' => true
),
'options' => array(
'title' => __( 'Additional Rates', 'woocommerce' ),
@ -152,12 +151,11 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
),
'minimum_fee' => array(
'title' => __( 'Minimum Handling Fee', 'woocommerce' ),
'type' => 'text',
'class' => 'wc_input_decimal',
'type' => 'price',
'placeholder' => wc_format_localized_price( 0 ),
'description' => __( 'Enter a minimum fee amount. Fee\'s less than this will be increased. Leave blank to disable.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
'placeholder' => '0.00'
'desc_tip' => true
),
);
@ -539,8 +537,8 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
<tr>
<td></td>
<td class="flat_rate_class"><?php _e( 'Any class', 'woocommerce' ); ?></td>
<td><input type="text" value="<?php echo esc_attr( $this->cost ); ?>" name="default_cost" placeholder="<?php _e( 'N/A', 'woocommerce' ); ?>" size="4" class="wc_input_decimal" /></td>
<td><input type="text" value="<?php echo esc_attr( $this->fee ); ?>" name="default_fee" placeholder="<?php _e( 'N/A', 'woocommerce' ); ?>" size="4" class="wc_input_decimal" /></td>
<td><input type="text" value="<?php echo esc_attr( wc_format_localized_price( $this->cost ) ); ?>" name="default_cost" placeholder="<?php _e( 'N/A', 'woocommerce' ); ?>" size="4" class="wc_input_price" /></td>
<td><input type="text" value="<?php echo esc_attr( wc_format_localized_price( $this->fee ) ); ?>" name="default_fee" placeholder="<?php _e( 'N/A', 'woocommerce' ); ?>" size="4" class="wc_input_price" /></td>
</tr>
<?php
$i = -1;
@ -563,8 +561,8 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
echo '</select>
</td>
<td><input type="text" value="' . esc_attr( $rate['cost'] ) . '" name="' . esc_attr( $this->id .'_cost[' . $i . ']' ) . '" placeholder="'.__( '0.00', 'woocommerce' ).'" size="4" class="wc_input_decimal" /></td>
<td><input type="text" value="' . esc_attr( $rate['fee'] ) . '" name="' . esc_attr( $this->id .'_fee[' . $i . ']' ) . '" placeholder="'.__( '0.00', 'woocommerce' ).'" size="4" class="wc_input_decimal" /></td>
<td><input type="text" value="' . esc_attr( $rate['cost'] ) . '" name="' . esc_attr( $this->id .'_cost[' . $i . ']' ) . '" placeholder="' . wc_format_localized_price( 0 ) . '" size="4" class="wc_input_price" /></td>
<td><input type="text" value="' . esc_attr( $rate['fee'] ) . '" name="' . esc_attr( $this->id .'_fee[' . $i . ']' ) . '" placeholder="' . wc_format_localized_price( 0 ) . '" size="4" class="wc_input_price" /></td>
</tr>';
}
}
@ -593,8 +591,8 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
?>\
</select>\
</td>\
<td><input type="text" name="<?php echo $this->id; ?>_cost[' + size + ']" placeholder="0.00" size="4" class="wc_input_decimal" /></td>\
<td><input type="text" name="<?php echo $this->id; ?>_fee[' + size + ']" placeholder="0.00" size="4" class="wc_input_decimal" /></td>\
<td><input type="text" name="<?php echo $this->id; ?>_cost[' + size + ']" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" size="4" class="wc_input_price" /></td>\
<td><input type="text" name="<?php echo $this->id; ?>_fee[' + size + ']" placeholder="<?php echo wc_format_localized_price( 0 ); ?>" size="4" class="wc_input_price" /></td>\
</tr>').appendTo('#<?php echo $this->id; ?>_flat_rates table tbody');
return false;
@ -645,10 +643,10 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
for ( $i = 0; $i <= $key; $i++ ) {
if ( ! empty( $flat_rate_class[ $i ] ) && isset( $flat_rate_cost[ $i ] ) && isset( $flat_rate_fee[ $i ] ) ) {
$flat_rate_cost[ $i ] = woocommerce_format_decimal( $flat_rate_cost[$i], 2 );
$flat_rate_cost[ $i ] = woocommerce_format_decimal( $flat_rate_cost[$i] );
if ( ! strstr( $flat_rate_fee[$i], '%' ) )
$flat_rate_fee[ $i ] = woocommerce_format_decimal( $flat_rate_fee[$i], 2 );
$flat_rate_fee[ $i ] = woocommerce_format_decimal( $flat_rate_fee[$i] );
else
$flat_rate_fee[ $i ] = woocommerce_clean( $flat_rate_fee[$i] );
@ -673,10 +671,10 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
* @return void
*/
function save_default_costs( $fields ) {
$default_cost = ( $_POST['default_cost'] === '' ) ? '' : woocommerce_format_decimal( $_POST['default_cost'], false );
$default_cost = ( $_POST['default_cost'] === '' ) ? '' : woocommerce_format_decimal( $_POST['default_cost'] );
if ( ! strstr( $_POST['default_fee'], '%' ) )
$default_fee = ( $_POST['default_fee'] === '' ) ? '' : woocommerce_format_decimal( $_POST['default_fee'], false );
$default_fee = ( $_POST['default_fee'] === '' ) ? '' : woocommerce_format_decimal( $_POST['default_fee'] );
else
$default_fee = woocommerce_clean( $_POST['default_fee'] );

View File

@ -109,12 +109,11 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
),
'min_amount' => array(
'title' => __( 'Minimum Order Amount', 'woocommerce' ),
'type' => 'text',
'class' => 'wc_input_decimal',
'type' => 'price',
'placeholder' => wc_format_localized_price( 0 ),
'description' => __( 'Users will need to spend this amount to get free shipping (if enabled above).', 'woocommerce' ),
'default' => '0',
'desc_tip' => true,
'placeholder' => '0.00'
'desc_tip' => true
)
);

View File

@ -101,12 +101,11 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
),
'cost' => array(
'title' => __( 'Cost', 'woocommerce' ),
'type' => 'text',
'class' => 'wc_input_decimal',
'type' => 'price',
'placeholder' => wc_format_localized_price( 0 ),
'description' => __( 'Cost excluding tax. Enter an amount, e.g. 2.50.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
'placeholder' => '0.00'
'desc_tip' => true
),
'fee' => array(
'title' => __( 'Handling Fee', 'woocommerce' ),
@ -114,16 +113,15 @@ class WC_Shipping_International_Delivery extends WC_Shipping_Flat_Rate {
'description' => __( 'Fee excluding tax. Enter an amount, e.g. 2.50, or a percentage, e.g. 5%. Leave blank to disable.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
'placeholder' => '0.00'
'placeholder' => wc_format_localized_price( 0 ),
),
'minimum_fee' => array(
'title' => __( 'Minimum Handling Fee', 'woocommerce' ),
'type' => 'text',
'class' => 'wc_input_decimal',
'type' => 'decimal',
'description' => __( 'Enter a minimum fee amount. Fee\'s less than this will be increased. Leave blank to disable.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
'placeholder' => '0.00'
'placeholder' => wc_format_localized_decimal( '0' )
),
);

View File

@ -121,12 +121,11 @@ class WC_Shipping_Local_Delivery extends WC_Shipping_Method {
),
'fee' => array(
'title' => __( 'Delivery Fee', 'woocommerce' ),
'type' => 'text',
'class' => 'wc_input_decimal',
'type' => 'price',
'description' => __( 'What fee do you want to charge for local delivery, disregarded if you choose free. Leave blank to disable.', 'woocommerce' ),
'default' => '',
'desc_tip' => true,
'placeholder' => '0.00'
'placeholder' => wc_format_localized_price( 0 )
),
'codes' => array(
'title' => __( 'Zip/Post Codes', 'woocommerce' ),

View File

@ -37,6 +37,19 @@ function woocommerce_readfile_chunked( $file, $retbytes = true ) {
return WC_Download_Handler::readfile_chunked( $file, $retbytes );
}
/**
* Formal total costs - format to the number of decimal places for the base currency.
*
* @access public
* @param mixed $number
* @deprecated 2.1
* @return string
*/
function woocommerce_format_total( $number ) {
_deprecated_function( __FUNCTION__, '2.1', 'woocommerce_format_decimal()' );
return woocommerce_format_decimal( $number, get_option( 'woocommerce_price_num_decimals' ), false );
}
/**
* Get product name with extra details such as SKU price and attributes. Used within admin.
*

View File

@ -175,34 +175,27 @@ function woocommerce_round_tax_total( $tax ) {
}
/**
* Format decimal numbers - format to a defined number of dp and remove trailing zeros.
* Format decimal numbers ready for DB storage
*
* Remove's user locale settings, converting to a string which uses '.' for decimals, with no thousand separators.
* Sanitize, remove locale formatting, and optionally round + trim off zeros
*
* @param float|string $number
* @param float|string $number Expects either a float or a string with a decimal separator only (no thousands)
* @param mixed $dp number of decimal points to use, blank to use woocommerce_price_num_decimals, or false to avoid all rounding.
* @param boolean $trim_zeros from end of string
* @return string
*/
function woocommerce_format_decimal( $number, $dp = '', $trim_zeros = false ) {
$number = floatval( $number );
function woocommerce_format_decimal( $number, $dp = false, $trim_zeros = false ) {
// Remove locale from string
if ( ! is_float( $number ) ) {
$locale = localeconv();
$decimals = array( get_option( 'woocommerce_price_decimal_sep' ), $locale['decimal_point'], $locale['mon_decimal_point'] );
$number = woocommerce_clean( str_replace( $decimals, '.', $number ) );
}
// DP is false - don't use number format, just remove locale settings from the number
if ( $dp === false ) {
$locale = localeconv();
$decimal = isset( $locale['decimal_point'] ) ? $locale['decimal_point'] : '.';
// Only allow numbers and the decimal point
if ( strstr( $number, $decimal ) )
$number = preg_replace( "/[^0-9\\" . $decimal . "]/", "", strval( $number ) );
else
$number = preg_replace( "/[^0-9.]/", "", strval( $number ) );
// Replace decimal point with .
$number = str_replace( $decimal, '.', $number );
} else {
$dp = ( $dp == "" ) ? intval( get_option( 'woocommerce_price_num_decimals' ) ) : intval( $dp );
$number = number_format( $number, $dp, '.', '' );
// DP is false - don't use number format, just return a string in our format
if ( $dp !== false ) {
$dp = intval( $dp == "" ? get_option( 'woocommerce_price_num_decimals' ) : $dp );
$number = number_format( floatval( $number ), $dp, '.', '' );
}
if ( $trim_zeros && strstr( $number, '.' ) )
@ -212,14 +205,38 @@ function woocommerce_format_decimal( $number, $dp = '', $trim_zeros = false ) {
}
/**
* Formal total costs - format to the number of decimal places for the base currency.
*
* @access public
* @param mixed $number
* Convert a float to a string without locale formatting which PHP adds when changing floats to strings
* @param float $float
* @return string
*/
function woocommerce_format_total( $number ) {
return woocommerce_format_decimal( $number, '', false );
function wc_float_to_string( $float ) {
if ( ! is_float( $float ) )
return $float;
$locale = localeconv();
$string = strval( $float );
$string = str_replace( $locale['decimal_point'], '.', $string );
return $string;
}
/**
* Format a price with WC Currency Locale settings
* @param string $value
* @return string
*/
function wc_format_localized_price( $value ) {
return str_replace( '.', get_option( 'woocommerce_price_decimal_sep' ), strval( $value ) );
}
/**
* Format a decimal with PHP Locale settings
* @param string $value
* @return string
*/
function wc_format_localized_decimal( $value ) {
$locale = localeconv();
return str_replace( '.', $locale['decimal_point'], strval( $value ) );
}
/**
@ -296,13 +313,13 @@ function woocommerce_price( $price, $args = array() ) {
), $args ) );
$return = '';
$num_decimals = (int) get_option( 'woocommerce_price_num_decimals' );
$num_decimals = absint( get_option( 'woocommerce_price_num_decimals' ) );
$currency_pos = get_option( 'woocommerce_currency_pos' );
$currency_symbol = get_woocommerce_currency_symbol();
$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 );
$price = apply_filters( 'raw_woocommerce_price', (double) $price );
$price = apply_filters( 'raw_woocommerce_price', floatval( $price ) );
$price = number_format( $price, $num_decimals, $decimal_sep, $thousands_sep );
if ( apply_filters( 'woocommerce_price_trim_zeros', true ) && $num_decimals > 0 )

View File

@ -911,9 +911,9 @@ function woocommerce_ajax_add_order_item() {
$item['name'] = $_product->get_title();
$item['tax_class'] = $_product->get_tax_class();
$item['qty'] = 1;
$item['line_subtotal'] = woocommerce_format_decimal( $_product->get_price_excluding_tax(), false );
$item['line_subtotal'] = woocommerce_format_decimal( $_product->get_price_excluding_tax() );
$item['line_subtotal_tax'] = '';
$item['line_total'] = woocommerce_format_decimal( $_product->get_price_excluding_tax(), false );
$item['line_total'] = woocommerce_format_decimal( $_product->get_price_excluding_tax() );
$item['line_tax'] = '';
// Add line item
@ -1192,9 +1192,9 @@ function woocommerce_calc_line_taxes() {
foreach( $items as $item_id => $item ) {
$item_id = absint( $item_id );
$line_subtotal = isset( $item['line_subtotal'] ) ? esc_attr( $item['line_subtotal'] ) : '';
$line_total = esc_attr( $item['line_total'] );
$tax_class = esc_attr( $item['tax_class'] );
$line_subtotal = isset( $item['line_subtotal'] ) ? woocommerce_format_decimal( $item['line_subtotal'] ) : 0;
$line_total = woocommerce_format_decimal( $item['line_total'] );
$tax_class = sanitize_text_field( $item['tax_class'] );
$product_id = $order->get_item_meta( $item_id, '_product_id', true );
if ( ! $item_id || $tax_class == '0' )
@ -1231,8 +1231,8 @@ function woocommerce_calc_line_taxes() {
$line_tax = 0;
$item_taxes[ $item_id ] = array(
'line_subtotal_tax' => $line_subtotal_tax,
'line_tax' => $line_tax
'line_subtotal_tax' => wc_format_localized_price( $line_subtotal_tax ),
'line_tax' => wc_format_localized_price( $line_tax )
);
$item_tax += $line_tax;
@ -1295,8 +1295,8 @@ function woocommerce_calc_line_taxes() {
$item['name'] = $tax_codes[ $key ];
$item['label'] = $tax->get_rate_label( $key );
$item['compound'] = $tax->is_compound( $key ) ? 1 : 0;
$item['tax_amount'] = woocommerce_format_decimal( isset( $taxes[ $key ] ) ? $taxes[ $key ] : 0, false );
$item['shipping_tax_amount'] = woocommerce_format_decimal( isset( $shipping_taxes[ $key ] ) ? $shipping_taxes[ $key ] : 0, false );
$item['tax_amount'] = woocommerce_format_decimal( isset( $taxes[ $key ] ) ? $taxes[ $key ] : 0 );
$item['shipping_tax_amount'] = woocommerce_format_decimal( isset( $shipping_taxes[ $key ] ) ? $shipping_taxes[ $key ] : 0 );
if ( ! $item['label'] )
$item['label'] = $woocommerce->countries->tax_or_vat();

View File

@ -273,6 +273,7 @@ final class WooCommerce {
include( 'includes/class-wc-install.php' );
include( 'includes/class-wc-download-handler.php' );
include( 'includes/class-wc-comments.php' );
include( 'includes/class-wc-post-data.php' );
if ( is_admin() )
include_once( 'includes/admin/class-wc-admin.php' );