diff --git a/assets/js/admin/meta-boxes.js b/assets/js/admin/meta-boxes.js
index a8ff6b3b8c4..299f7e3cf33 100644
--- a/assets/js/admin/meta-boxes.js
+++ b/assets/js/admin/meta-boxes.js
@@ -213,10 +213,10 @@ jQuery( function($){
var line_subtotal_tax = $row.find('input.line_subtotal_tax').val();
if ( qty ) {
- unit_subtotal = accounting.toFixed( ( line_subtotal / qty ), 2 );
- unit_subtotal_tax = accounting.toFixed( ( line_subtotal_tax / qty ), 2 );
- unit_total = accounting.toFixed( ( line_total / qty ), 2 );
- unit_total_tax = accounting.toFixed( ( line_tax / qty ), 2 );
+ unit_subtotal = parseFloat( accounting.toFixed( ( line_subtotal / qty ), woocommerce_admin_meta_boxes.rounding_precision ) );
+ unit_subtotal_tax = parseFloat( accounting.toFixed( ( line_subtotal_tax / qty ), woocommerce_admin_meta_boxes.rounding_precision ) );
+ unit_total = parseFloat( accounting.toFixed( ( line_total / qty ), woocommerce_admin_meta_boxes.rounding_precision ) );
+ unit_total_tax = parseFloat( accounting.toFixed( ( line_tax / qty ), woocommerce_admin_meta_boxes.rounding_precision ) );
} else {
unit_subtotal = unit_subtotal_tax = unit_total = unit_total_tax = 0;
}
@@ -252,10 +252,10 @@ jQuery( function($){
var unit_total_tax = $row.attr('data-unit_total_tax');
var o_qty = $(this).attr('data-o_qty');
- var subtotal = accounting.formatNumber( unit_subtotal * qty, 2, '' );
- var tax = accounting.formatNumber( unit_subtotal_tax * qty, 2, '' );
- var total = accounting.formatNumber( unit_total * qty, 2, '' );
- var total_tax = accounting.formatNumber( unit_total_tax * qty, 2, '' );
+ var subtotal = parseFloat( accounting.formatNumber( unit_subtotal * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) );
+ var tax = parseFloat( accounting.formatNumber( unit_subtotal_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) );
+ var total = parseFloat( accounting.formatNumber( unit_total * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) );
+ var total_tax = parseFloat( accounting.formatNumber( unit_total_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) );
$row.find('input.line_subtotal').val( subtotal );
$row.find('input.line_total').val( total );
@@ -270,7 +270,7 @@ jQuery( function($){
var $row = $(this).closest('tr.item');
var $qty = $row.find('input.quantity');
var qty = $qty.val();
- var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0;
+ var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), woocommerce_admin_meta_boxes.rounding_precision ) : 0;
$row.attr( 'data-unit_subtotal', value );
});
@@ -280,7 +280,7 @@ jQuery( function($){
var $row = $(this).closest('tr.item');
var $qty = $row.find('input.quantity');
var qty = $qty.val();
- var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0;
+ var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), woocommerce_admin_meta_boxes.rounding_precision ) : 0;
$row.attr( 'data-unit_total', value );
});
@@ -290,7 +290,7 @@ jQuery( function($){
var $row = $(this).closest('tr.item');
var $qty = $row.find('input.quantity');
var qty = $qty.val();
- var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0;
+ var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), woocommerce_admin_meta_boxes.rounding_precision ) : 0;
$row.attr( 'data-unit_subtotal_tax', value );
});
@@ -300,7 +300,7 @@ jQuery( function($){
var $row = $(this).closest('tr.item');
var $qty = $row.find('input.quantity');
var qty = $qty.val();
- var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), 2 ) : 0;
+ var value = ( qty ) ? accounting.toFixed( ( $(this).val() / qty ), woocommerce_admin_meta_boxes.rounding_precision ) : 0;
$row.attr( 'data-unit_total_tax', value );
});
@@ -309,7 +309,7 @@ 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]');
+ var fields = $this.closest('.totals_group').find('input[type=number], .wc_input_decimal');
var total = 0;
fields.each(function(){
@@ -317,6 +317,10 @@ jQuery( function($){
total = total + parseFloat( $(this).val() );
});
+ if ( $this.is('.order_taxes_amount') || $this.is('.order_taxes_shipping_amount') ) {
+ total = round( total, woocommerce_admin_meta_boxes.currency_format_num_decimals, woocommerce_admin_meta_boxes.tax_rounding_mode );
+ }
+
var formatted_total = accounting.formatMoney( total, {
symbol : woocommerce_admin_meta_boxes.currency_format_symbol,
decimal : woocommerce_admin_meta_boxes.currency_format_decimal_sep,
@@ -381,7 +385,7 @@ jQuery( function($){
order_shipping = 0;
- $('#shipping_rows').find('input[type=number]').each(function(){
+ $('#shipping_rows').find('input[type=number], .wc_input_decimal').each(function(){
cost = $(this).val() || '0';
cost = accounting.unformat( cost.replace(',', '.') );
order_shipping = order_shipping + parseFloat( cost );
@@ -445,13 +449,13 @@ jQuery( function($){
order_discount = accounting.unformat( order_discount.replace(',', '.') );
- $('#shipping_rows').find('input[type=number]').each(function(){
+ $('#shipping_rows').find('input[type=number], .wc_input_decimal').each(function(){
cost = $(this).val() || '0';
cost = accounting.unformat( cost.replace(',', '.') );
shipping = shipping + parseFloat( cost );
});
- $('#tax_rows').find('input[type=number]').each(function(){
+ $('#tax_rows').find('input[type=number], .wc_input_decimal').each(function(){
cost = $(this).val() || '0';
cost = accounting.unformat( cost.replace(',', '.') );
tax = tax + parseFloat( cost );
@@ -464,10 +468,10 @@ jQuery( function($){
// Tax
if ( woocommerce_admin_meta_boxes.round_at_subtotal == 'yes' )
- tax = parseFloat( accounting.toFixed( tax, 2 ) );
+ tax = parseFloat( accounting.toFixed( tax, woocommerce_admin_meta_boxes.rounding_precision ) );
// Set Total
- $('#_order_total').val( accounting.toFixed( line_totals + tax + shipping - order_discount, 2 ) ).change();
+ $('#_order_total').val( parseFloat( accounting.toFixed( line_totals + tax + shipping - order_discount, woocommerce_admin_meta_boxes.currency_format_num_decimals ) ) ).change();
}
$('#woocommerce-order-totals').unblock();
diff --git a/assets/js/admin/meta-boxes.min.js b/assets/js/admin/meta-boxes.min.js
index 8e533d9dd4f..4ae56fab307 100644
--- a/assets/js/admin/meta-boxes.min.js
+++ b/assets/js/admin/meta-boxes.min.js
@@ -1 +1 @@
-jQuery(function(e){function t(){var t=e("select#product-type").val(),n=e("input#_virtual:checked").size(),r=e("input#_downloadable:checked").size(),i=".hide_if_downloadable, .hide_if_virtual",s=".show_if_downloadable, .show_if_virtual, .show_if_external";e.each(woocommerce_admin_meta_boxes.product_types,function(e,t){i=i+", .hide_if_"+t;s=s+", .show_if_"+t});e(i).show();e(s).hide();r&&e(".show_if_downloadable").show();n&&e(".show_if_virtual").show();e(".show_if_"+t).show();r&&e(".hide_if_downloadable").hide();n&&e(".hide_if_virtual").hide();e(".hide_if_"+t).hide();e("input#_manage_stock").change()}function i(){e(".woocommerce_attributes .woocommerce_attribute").each(function(t,n){e(".attribute_position",n).val(parseInt(e(n).index(".woocommerce_attributes .woocommerce_attribute")))})}e("#titlediv #title").keyup(function(t){var n=t.keyCode||t.which;if(n=="9"&&e("#woocommerce-coupon-description").size()>0){t.stopPropagation();e("#woocommerce-coupon-description").focus();return!1}});e("select#discount_type").change(function(){var t=e(this).val();t=="fixed_product"||t=="percent_product"?e(".limit_usage_to_x_items_field").show():e(".limit_usage_to_x_items_field").hide()}).change();e(function(){e('[id$="-all"] > ul.categorychecklist').each(function(){var t=e(this),n=t.find(":checked").first();if(!n.length)return;var r=t.find("input").position().top,i=n.position().top;t.closest(".tabs-panel").scrollTop(i-r+5)})});e("#upsell_product_data").bind("keypress",function(e){if(e.keyCode==13)return!1});e(".type_box").appendTo("#woocommerce-product-data h3.hndle span");e(function(){e("#woocommerce-product-data h3.hndle").unbind("click.postboxes");jQuery("#woocommerce-product-data").on("click","h3.hndle",function(t){if(e(t.target).filter("input, option, label, select").length)return;e("#woocommerce-product-data").toggleClass("closed")})});e("#order-emails a.show-order-emails").click(function(){if(e("#order-emails-select").is(":hidden")){e("#order-emails-select").slideDown("fast");e(this).hide()}return!1});e("#order-emails a.hide-order-emails").click(function(){e('input[name="order_email[]"]').each(function(){e(this).attr("checked",!1)});if(e("#order-emails-select").is(":visible")){e("#order-emails-select").slideUp("fast");e("#order-emails a.show-order-emails").show()}return!1});e("#catalog-visibility .edit-catalog-visibility").click(function(){if(e("#catalog-visibility-select").is(":hidden")){e("#catalog-visibility-select").slideDown("fast");e(this).hide()}return!1});e("#catalog-visibility .save-post-visibility").click(function(){e("#catalog-visibility-select").slideUp("fast");e("#catalog-visibility .edit-catalog-visibility").show();var t=e("input[name=_visibility]:checked").val(),n=e("input[name=_visibility]:checked").attr("data-label");if(e("input[name=_featured]").is(":checked")){n=n+", "+woocommerce_admin_meta_boxes.featured_label;e("input[name=_featured]").attr("checked","checked")}e("#catalog-visibility-display").text(n);return!1});e("#catalog-visibility .cancel-post-visibility").click(function(){e("#catalog-visibility-select").slideUp("fast");e("#catalog-visibility .edit-catalog-visibility").show();var t=e("#current_visibility").val(),n=e("#current_featured").val();e("input[name=_visibility]").removeAttr("checked");e("input[name=_visibility][value="+t+"]").attr("checked","checked");var r=e("input[name=_visibility]:checked").attr("data-label");if(n=="yes"){r=r+", "+woocommerce_admin_meta_boxes.featured_label;e("input[name=_featured]").attr("checked","checked")}else e("input[name=_featured]").removeAttr("checked");e("#catalog-visibility-display").text(r);return!1});e("ul.wc-tabs").show();e("div.panel-wrap").each(function(){e(this).find("div.panel:not(:first)").hide()});e("ul.wc-tabs a").click(function(){var t=e(this).closest("div.panel-wrap");e("ul.wc-tabs li",t).removeClass("active");e(this).parent().addClass("active");e("div.panel",t).hide();e(e(this).attr("href")).show();return!1});jQuery("select.chosen_select").chosen();jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"});jQuery("select.ajax_chosen_select_products").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(t){var n={};e.each(t,function(e,t){n[e]=t});return n});jQuery("select.ajax_chosen_select_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(t){var n={};e.each(t,function(e,t){n[e]=t});return n});jQuery("#woocommerce-order-actions input, #woocommerce-order-actions a").click(function(){window.onbeforeunload=""});e("a.edit_address").click(function(t){e(this).hide();e(this).closest(".order_data_column").find("div.address").hide();e(this).closest(".order_data_column").find("div.edit_address").show();t.preventDefault()});e("#order_items_list").on("init_row","tr.item",function(){var t=e(this),n=t.find("input.quantity"),r=n.val(),i=t.find("input.line_subtotal").val(),s=t.find("input.line_total").val(),o=t.find("input.line_tax").val(),u=t.find("input.line_subtotal_tax").val();if(r){unit_subtotal=accounting.toFixed(i/r,2);unit_subtotal_tax=accounting.toFixed(u/r,2);unit_total=accounting.toFixed(s/r,2);unit_total_tax=accounting.toFixed(o/r,2)}else unit_subtotal=unit_subtotal_tax=unit_total=unit_total_tax=0;n.attr("data-o_qty",r);t.attr("data-unit_subtotal",unit_subtotal);t.attr("data-unit_subtotal_tax",unit_subtotal_tax);t.attr("data-unit_total",unit_total);t.attr("data-unit_total_tax",unit_total_tax)});e("#order_items_list tr.item").each(function(){e(this).trigger("init_row");e(this).find(".edit").hide()});e("#order_items_list").on("click","a.edit_order_item",function(){e(this).closest("tr").find(".view").hide();e(this).closest("tr").find(".edit").show();e(this).hide();return!1});e("#order_items_list").on("change","input.quantity",function(){var t=e(this).closest("tr.item"),n=e(this).val(),r=t.attr("data-unit_subtotal"),i=t.attr("data-unit_subtotal_tax"),s=t.attr("data-unit_total"),o=t.attr("data-unit_total_tax"),u=e(this).attr("data-o_qty"),a=accounting.formatNumber(r*n,2,""),f=accounting.formatNumber(i*n,2,""),l=accounting.formatNumber(s*n,2,""),c=accounting.formatNumber(o*n,2,"");t.find("input.line_subtotal").val(a);t.find("input.line_total").val(l);t.find("input.line_subtotal_tax").val(f);t.find("input.line_tax").val(c);e(this).trigger("quantity_changed")});e("#order_items_list").on("change","input.line_subtotal",function(){var t=e(this).closest("tr.item"),n=t.find("input.quantity"),r=n.val(),i=r?accounting.toFixed(e(this).val()/r,2):0;t.attr("data-unit_subtotal",i)});e("#order_items_list").on("change","input.line_total",function(){var t=e(this).closest("tr.item"),n=t.find("input.quantity"),r=n.val(),i=r?accounting.toFixed(e(this).val()/r,2):0;t.attr("data-unit_total",i)});e("#order_items_list").on("change","input.line_subtotal_tax",function(){var t=e(this).closest("tr.item"),n=t.find("input.quantity"),r=n.val(),i=r?accounting.toFixed(e(this).val()/r,2):0;t.attr("data-unit_subtotal_tax",i)});e("#order_items_list").on("change","input.line_tax",function(){var t=e(this).closest("tr.item"),n=t.find("input.quantity"),r=n.val(),i=r?accounting.toFixed(e(this).val()/r,2):0;t.attr("data-unit_total_tax",i)});e("#woocommerce-order-totals").on("change input",".order_taxes_amount, .order_taxes_shipping_amount, .shipping_cost, #_order_discount",function(){var t=e(this),n=t.closest(".totals_group").find("input[type=number]"),r=0;n.each(function(){e(this).val()&&(r+=parseFloat(e(this).val()))});var i=accounting.formatMoney(r,{symbol:woocommerce_admin_meta_boxes.currency_format_symbol,decimal:woocommerce_admin_meta_boxes.currency_format_decimal_sep,thousand:woocommerce_admin_meta_boxes.currency_format_thousand_sep,precision:woocommerce_admin_meta_boxes.currency_format_num_decimals,format:woocommerce_admin_meta_boxes.currency_format});t.closest(".totals_group").find("span.inline_total").text(i)});e("span.inline_total").closest(".totals_group").find("input").change();e("button.calc_line_taxes").click(function(){e(".woocommerce_order_items_wrapper").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t=confirm(woocommerce_admin_meta_boxes.calc_line_taxes);if(t){var n=e("#order_items_list").find("tr.item, tr.fee"),r=e("#_shipping_country").val(),i=e("#_billing_country").val();if(r)var s=r,o=e("#_shipping_state").val(),u=e("#_shipping_postcode").val(),a=e("#_shipping_city").val();else if(i)var s=i,o=e("#_billing_state").val(),u=e("#_billing_postcode").val(),a=e("#_billing_city").val();else var s=woocommerce_admin_meta_boxes.base_country,o="",u="",a="";var f={};n.each(function(){var t=e(this),n=t.find("input.order_item_id").val(),r=t.find("input.line_subtotal").val(),i=t.find("input.line_total").val(),s=t.find("select.tax_class").val();f[n]={};f[n].line_subtotal=r;f[n].line_total=i;f[n].tax_class=s});order_shipping=0;e("#shipping_rows").find("input[type=number]").each(function(){cost=e(this).val()||"0";cost=accounting.unformat(cost.replace(",","."));order_shipping+=parseFloat(cost)});var l={action:"woocommerce_calc_line_taxes",order_id:woocommerce_admin_meta_boxes.post_id,items:f,shipping:order_shipping,country:s,state:o,postcode:u,city:a,security:woocommerce_admin_meta_boxes.calc_totals_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,l,function(t){if(t){n.each(function(){var n=e(this),r=n.find("input.order_item_id").val();n.find(".edit_order_item").click();if(t.item_taxes[r]){n.find("input.line_tax").val(t.item_taxes[r].line_tax).change();n.find("input.line_subtotal_tax").val(t.item_taxes[r].line_subtotal_tax).change()}t.tax_row_html&&e("#tax_rows").empty().append(t.tax_row_html)});e("#tax_rows").find("input").change()}e(".woocommerce_order_items_wrapper").unblock()})}else e(".woocommerce_order_items_wrapper").unblock();return!1});e("button.calc_totals").click(function(){e("#woocommerce-order-totals").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t=confirm(woocommerce_admin_meta_boxes.calc_totals);if(t){var n=0,r=0,i=0,s=e("#_order_discount").val()||"0";s=accounting.unformat(s.replace(",","."));e("#shipping_rows").find("input[type=number]").each(function(){cost=e(this).val()||"0";cost=accounting.unformat(cost.replace(",","."));i+=parseFloat(cost)});e("#tax_rows").find("input[type=number]").each(function(){cost=e(this).val()||"0";cost=accounting.unformat(cost.replace(",","."));r+=parseFloat(cost)});e("#order_items_list tr.item, #order_items_list tr.fee").each(function(){line_total=e(this).find("input.line_total").val()||"0";n+=accounting.unformat(line_total.replace(",","."))});woocommerce_admin_meta_boxes.round_at_subtotal=="yes"&&(r=parseFloat(accounting.toFixed(r,2)));e("#_order_total").val(accounting.toFixed(n+r+i-s,2)).change()}e("#woocommerce-order-totals").unblock();return!1});e("#woocommerce-order-items button.add_order_item").click(function(){var t=e("select#add_item_id").val();if(t){count=t.length;e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.each(t,function(t,n){var r={action:"woocommerce_add_order_item",item_to_add:n,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,r,function(t){e("table.woocommerce_order_items tbody#order_items_list").append(t);if(!--count){e("select#add_item_id, #add_item_id_chosen .chosen-choices").css("border-color","").val("");jQuery(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200});e("select#add_item_id").trigger("chosen:updated");e("table.woocommerce_order_items").unblock()}e("#order_items_list tr.new_row").trigger("init_row").removeClass("new_row")})})}else e("select#add_item_id, #add_item_id_chosen .chosen-choices").css("border-color","red");return!1});e("#woocommerce-order-items button.add_order_fee").click(function(){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t={action:"woocommerce_add_order_fee",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,t,function(t){e("table.woocommerce_order_items tbody#order_items_list").append(t);e("table.woocommerce_order_items").unblock()});return!1});e("#order_items_list").on("click","button.add_order_item_meta",function(){var t=e(this),n=t.closest("tr.item"),r={order_item_id:n.attr("data-order_item_id"),action:"woocommerce_add_order_item_meta",security:woocommerce_admin_meta_boxes.order_item_nonce};e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(t){n.find("tbody.meta_items").append(t);e("table.woocommerce_order_items").unblock()}});return!1});e("#order_items_list").on("click","button.remove_order_item_meta",function(){var t=confirm(woocommerce_admin_meta_boxes.remove_item_meta);if(t){var n=e(this).closest("tr"),r={meta_id:n.attr("data-meta_id"),action:"woocommerce_remove_order_item_meta",security:woocommerce_admin_meta_boxes.order_item_nonce};e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(t){n.hide();e("table.woocommerce_order_items").unblock()}})}return!1});e("#woocommerce-order-items").on("click","input.check-column",function(){e(this).is(":checked")?e("#woocommerce-order-items").find(".check-column input").attr("checked","checked"):e("#woocommerce-order-items").find(".check-column input").removeAttr("checked")});e("#woocommerce-order-items").on("click",".do_bulk_action",function(){var t=e(this).closest(".bulk_actions").find("select").val(),n=e("#woocommerce-order-items").find(".check-column input:checked"),r=[];e(n).each(function(){var t=e(this).closest("tr.item, tr.fee");r.push(t.attr("data-order_item_id"))});if(r.length==0){alert(woocommerce_admin_meta_boxes.i18n_select_items);return}if(t=="delete"){var i=confirm(woocommerce_admin_meta_boxes.remove_item_notice);if(i){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var s={order_item_ids:r,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:s,type:"POST",success:function(t){e(n).each(function(){e(this).closest("tr.item, tr.fee").remove()});e("table.woocommerce_order_items").unblock()}})}}else if(t=="reduce_stock"){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var o={};e(n).each(function(){var t=e(this).closest("tr.item, tr.fee"),n=t.find("input.quantity");o[t.attr("data-order_item_id")]=n.val()});var s={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:r,order_item_qty:o,action:"woocommerce_reduce_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:s,type:"POST",success:function(t){alert(t);e("table.woocommerce_order_items").unblock()}})}else if(t=="increase_stock"){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var o={};e(n).each(function(){var t=e(this).closest("tr.item, tr.fee"),n=t.find("input.quantity");o[t.attr("data-order_item_id")]=n.val()});var s={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:r,order_item_qty:o,action:"woocommerce_increase_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:s,type:"POST",success:function(t){alert(t);e("table.woocommerce_order_items").unblock()}})}return!1});e("button.load_customer_billing").click(function(){var t=confirm(woocommerce_admin_meta_boxes.load_billing);if(t){var n=e("#customer_user").val();if(!n){alert(woocommerce_admin_meta_boxes.no_customer_selected);return!1}var r={user_id:n,type_to_load:"billing",action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};e(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(t){var n=t;if(n){e("input#_billing_first_name").val(n.billing_first_name);e("input#_billing_last_name").val(n.billing_last_name);e("input#_billing_company").val(n.billing_company);e("input#_billing_address_1").val(n.billing_address_1);e("input#_billing_address_2").val(n.billing_address_2);e("input#_billing_city").val(n.billing_city);e("input#_billing_postcode").val(n.billing_postcode);e("#_billing_country").val(n.billing_country);e("input#_billing_state").val(n.billing_state);e("input#_billing_email").val(n.billing_email);e("input#_billing_phone").val(n.billing_phone)}e(".edit_address").unblock()}})}return!1});e("button.load_customer_shipping").click(function(){var t=confirm(woocommerce_admin_meta_boxes.load_shipping);if(t){var n=e("#customer_user").val();if(!n){alert(woocommerce_admin_meta_boxes.no_customer_selected);return!1}var r={user_id:n,type_to_load:"shipping",action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};e(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(t){var n=t;if(n){e("input#_shipping_first_name").val(n.shipping_first_name);e("input#_shipping_last_name").val(n.shipping_last_name);e("input#_shipping_company").val(n.shipping_company);e("input#_shipping_address_1").val(n.shipping_address_1);e("input#_shipping_address_2").val(n.shipping_address_2);e("input#_shipping_city").val(n.shipping_city);e("input#_shipping_postcode").val(n.shipping_postcode);e("#_shipping_country").val(n.shipping_country);e("input#_shipping_state").val(n.shipping_state)}e(".edit_address").unblock()}})}return!1});e("button.billing-same-as-shipping").click(function(){var t=confirm(woocommerce_admin_meta_boxes.copy_billing);if(t){e("input#_shipping_first_name").val(e("input#_billing_first_name").val());e("input#_shipping_last_name").val(e("input#_billing_last_name").val());e("input#_shipping_company").val(e("input#_billing_company").val());e("input#_shipping_address_1").val(e("input#_billing_address_1").val());e("input#_shipping_address_2").val(e("input#_billing_address_2").val());e("input#_shipping_city").val(e("input#_billing_city").val());e("input#_shipping_postcode").val(e("input#_billing_postcode").val());e("#_shipping_country").val(e("#_billing_country").val());e("input#_shipping_state").val(e("input#_billing_state").val())}return!1});e(".totals_group").on("click","a.add_total_row",function(){e(this).closest(".totals_group").find(".total_rows").append(e(this).data("row"));return!1});e(".total_rows").on("click","a.delete_total_row",function(){$row=e(this).closest(".total_row");var t=$row.attr("data-order_item_id");t?$row.append('').hide():$row.remove();return!1});e("select#product-type").change(function(){var n=e(this).val();if(n=="variable"){e("input#_manage_stock").change();e("input#_downloadable").prop("checked",!1);e("input#_virtual").removeAttr("checked")}else if(n=="grouped"){e("input#_downloadable").prop("checked",!1);e("input#_virtual").removeAttr("checked")}else if(n=="external"){e("input#_downloadable").prop("checked",!1);e("input#_virtual").removeAttr("checked")}t();e("ul.wc-tabs li:visible").eq(0).find("a").click();e("body").trigger("woocommerce-product-type-change",n,e(this))}).change();e("ul.wc-tabs li:visible").eq(0).find("a").click();e("input#_downloadable, input#_virtual").change(function(){t()});e(".sale_price_dates_fields").each(function(){var t=e(this),n=!1,r=t.closest("div, table");t.find("input").each(function(){e(this).val()!=""&&(n=!0)});if(n){r.find(".sale_schedule").hide();r.find(".sale_price_dates_fields").show()}else{r.find(".sale_schedule").show();r.find(".sale_price_dates_fields").hide()}});e("#woocommerce-product-data").on("click",".sale_schedule",function(){var t=e(this).closest("div, table");e(this).hide();t.find(".cancel_sale_schedule").show();t.find(".sale_price_dates_fields").show();return!1});e("#woocommerce-product-data").on("click",".cancel_sale_schedule",function(){var t=e(this).closest("div, table");e(this).hide();t.find(".sale_schedule").show();t.find(".sale_price_dates_fields").hide();t.find(".sale_price_dates_fields").find("input").val("");return!1});e(".downloadable_files").on("click","a.insert",function(){e(this).closest(".downloadable_files").find("tbody").append(e(this).data("row"));return!1});e(".downloadable_files").on("click","a.delete",function(){e(this).closest("tr").remove();return!1});e("input#_manage_stock").change(function(){e(this).is(":checked")?e("div.stock_fields").show():e("div.stock_fields").hide()}).change();var n=e(".sale_price_dates_fields input").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_admin_meta_boxes.calendar_image,buttonImageOnly:!0,onSelect:function(t){var r=e(this).is("#_sale_price_dates_from, .sale_price_dates_from")?"minDate":"maxDate",i=e(this).data("datepicker"),s=e.datepicker.parseDate(i.settings.dateFormat||e.datepicker._defaults.dateFormat,t,i.settings);n.not(this).datepicker("option",r,s)}});e(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_admin_meta_boxes.calendar_image,buttonImageOnly:!0});e(".date-picker-field").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0});jQuery(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(t){if(e(t.target).filter(":input, option").length)return;jQuery(this).next(".wc-metabox-content").toggle()}).on("click",".expand_all",function(e){jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").show();return!1}).on("click",".close_all",function(e){jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").hide();return!1});jQuery(".wc-metabox.closed").each(function(){jQuery(this).find(".wc-metabox-content").hide()});e(".woocommerce_attributes select.multiselect").chosen();var r=e(".woocommerce_attributes").find(".woocommerce_attribute").get();r.sort(function(t,n){var r=parseInt(e(t).attr("rel")),i=parseInt(e(n).attr("rel"));return ri?1:0});e(r).each(function(t,n){e(".woocommerce_attributes").append(n)});e("button.add_attribute").on("click",function(){var t=e(".woocommerce_attributes .woocommerce_attribute").size(),n=e("select.attribute_taxonomy").val();if(!n){var r=e("select#product-type").val();r!="variable"?enable_variation='style="display:none;"':enable_variation="";e(".woocommerce_attributes").append('")}else{var s=e(".woocommerce_attributes .woocommerce_attribute."+n);e(".woocommerce_attributes").append(e(s));e(s).show().find(".woocommerce_attribute_data").show();i()}e("select.attribute_taxonomy").val("")});e(".woocommerce_attributes").on("blur","input.attribute_name",function(){e(this).closest(".woocommerce_attribute").find("strong.attribute_name").text(e(this).val())});e(".woocommerce_attributes").on("click","button.select_all_attributes",function(){e(this).closest("td").find("select option").attr("selected","selected");e(this).closest("td").find("select").trigger("chosen:updated");return!1});e(".woocommerce_attributes").on("click","button.select_no_attributes",function(){e(this).closest("td").find("select option").removeAttr("selected");e(this).closest("td").find("select").trigger("chosen:updated");return!1});e(".woocommerce_attributes").on("click","button.remove_row",function(){var t=confirm(woocommerce_admin_meta_boxes.remove_attribute);if(t){var n=e(this).parent().parent();if(n.is(".taxonomy")){n.find("select, input[type=text]").val("");n.hide()}else{n.find("select, input[type=text]").val("");n.hide();i()}}return!1});e(".woocommerce_attributes").sortable({items:".woocommerce_attribute",cursor:"move",axis:"y",handle:"h3",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");i()}});e(".woocommerce_attributes").on("click","button.add_new_attribute",function(){e(".woocommerce_attributes").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t=e(this).attr("data-attribute"),n=e(this).closest(".woocommerce_attribute_data"),r=prompt(woocommerce_admin_meta_boxes.new_attribute_prompt);if(r){var i={action:"woocommerce_add_new_attribute",taxonomy:t,term:r,security:woocommerce_admin_meta_boxes.add_attribute_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,i,function(t){if(t.error)alert(t.error);else if(t.slug){n.find("select.attribute_values").append('");n.find("select.attribute_values").trigger("chosen:updated")}e(".woocommerce_attributes").unblock()})}else e(".woocommerce_attributes").unblock();return!1});e(".save_attributes").on("click",function(){e(".woocommerce_attributes").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t={post_id:woocommerce_admin_meta_boxes.post_id,data:e(".woocommerce_attributes").find("input, select, textarea").serialize(),action:"woocommerce_save_attributes",security:woocommerce_admin_meta_boxes.save_attributes_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,t,function(t){var n=window.location.toString();n=n.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&");e("#variable_product_options").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e("#variable_product_options").load(n+" #variable_product_options_inner",function(){e("#variable_product_options").unblock()});e(".woocommerce_attributes").unblock()})});var s,o;jQuery(document).on("click",".upload_file_button",function(t){var n=e(this);o=n.closest("tr").find("td.file_url input");t.preventDefault();if(s){s.open();return}var r=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:n.data("choose"),priority:20,filterable:"uploaded"})];s=wp.media.frames.downloadable_file=wp.media({title:n.data("choose"),library:{type:""},button:{text:n.data("update")},multiple:!0,states:r});s.on("select",function(){var e="",t=s.state().get("selection");t.map(function(t){t=t.toJSON();t.url&&(e=t.url)});o.val(e)});s.on("ready",function(){s.uploader.options.uploader.params={type:"downloadable_product"}});s.open()});jQuery(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65})});
\ No newline at end of file
+jQuery(function(e){function t(){var t=e("select#product-type").val(),n=e("input#_virtual:checked").size(),r=e("input#_downloadable:checked").size(),i=".hide_if_downloadable, .hide_if_virtual",s=".show_if_downloadable, .show_if_virtual, .show_if_external";e.each(woocommerce_admin_meta_boxes.product_types,function(e,t){i=i+", .hide_if_"+t;s=s+", .show_if_"+t});e(i).show();e(s).hide();r&&e(".show_if_downloadable").show();n&&e(".show_if_virtual").show();e(".show_if_"+t).show();r&&e(".hide_if_downloadable").hide();n&&e(".hide_if_virtual").hide();e(".hide_if_"+t).hide();e("input#_manage_stock").change()}function i(){e(".woocommerce_attributes .woocommerce_attribute").each(function(t,n){e(".attribute_position",n).val(parseInt(e(n).index(".woocommerce_attributes .woocommerce_attribute")))})}e("#titlediv #title").keyup(function(t){var n=t.keyCode||t.which;if(n=="9"&&e("#woocommerce-coupon-description").size()>0){t.stopPropagation();e("#woocommerce-coupon-description").focus();return!1}});e("select#discount_type").change(function(){var t=e(this).val();t=="fixed_product"||t=="percent_product"?e(".limit_usage_to_x_items_field").show():e(".limit_usage_to_x_items_field").hide()}).change();e(function(){e('[id$="-all"] > ul.categorychecklist').each(function(){var t=e(this),n=t.find(":checked").first();if(!n.length)return;var r=t.find("input").position().top,i=n.position().top;t.closest(".tabs-panel").scrollTop(i-r+5)})});e("#upsell_product_data").bind("keypress",function(e){if(e.keyCode==13)return!1});e(".type_box").appendTo("#woocommerce-product-data h3.hndle span");e(function(){e("#woocommerce-product-data h3.hndle").unbind("click.postboxes");jQuery("#woocommerce-product-data").on("click","h3.hndle",function(t){if(e(t.target).filter("input, option, label, select").length)return;e("#woocommerce-product-data").toggleClass("closed")})});e("#order-emails a.show-order-emails").click(function(){if(e("#order-emails-select").is(":hidden")){e("#order-emails-select").slideDown("fast");e(this).hide()}return!1});e("#order-emails a.hide-order-emails").click(function(){e('input[name="order_email[]"]').each(function(){e(this).attr("checked",!1)});if(e("#order-emails-select").is(":visible")){e("#order-emails-select").slideUp("fast");e("#order-emails a.show-order-emails").show()}return!1});e("#catalog-visibility .edit-catalog-visibility").click(function(){if(e("#catalog-visibility-select").is(":hidden")){e("#catalog-visibility-select").slideDown("fast");e(this).hide()}return!1});e("#catalog-visibility .save-post-visibility").click(function(){e("#catalog-visibility-select").slideUp("fast");e("#catalog-visibility .edit-catalog-visibility").show();var t=e("input[name=_visibility]:checked").val(),n=e("input[name=_visibility]:checked").attr("data-label");if(e("input[name=_featured]").is(":checked")){n=n+", "+woocommerce_admin_meta_boxes.featured_label;e("input[name=_featured]").attr("checked","checked")}e("#catalog-visibility-display").text(n);return!1});e("#catalog-visibility .cancel-post-visibility").click(function(){e("#catalog-visibility-select").slideUp("fast");e("#catalog-visibility .edit-catalog-visibility").show();var t=e("#current_visibility").val(),n=e("#current_featured").val();e("input[name=_visibility]").removeAttr("checked");e("input[name=_visibility][value="+t+"]").attr("checked","checked");var r=e("input[name=_visibility]:checked").attr("data-label");if(n=="yes"){r=r+", "+woocommerce_admin_meta_boxes.featured_label;e("input[name=_featured]").attr("checked","checked")}else e("input[name=_featured]").removeAttr("checked");e("#catalog-visibility-display").text(r);return!1});e("ul.wc-tabs").show();e("div.panel-wrap").each(function(){e(this).find("div.panel:not(:first)").hide()});e("ul.wc-tabs a").click(function(){var t=e(this).closest("div.panel-wrap");e("ul.wc-tabs li",t).removeClass("active");e(this).parent().addClass("active");e("div.panel",t).hide();e(e(this).attr("href")).show();return!1});jQuery("select.chosen_select").chosen();jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"});jQuery("select.ajax_chosen_select_products").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(t){var n={};e.each(t,function(e,t){n[e]=t});return n});jQuery("select.ajax_chosen_select_products_and_variations").ajaxChosen({method:"GET",url:woocommerce_admin_meta_boxes.ajax_url,dataType:"json",afterTypeDelay:100,data:{action:"woocommerce_json_search_products_and_variations",security:woocommerce_admin_meta_boxes.search_products_nonce}},function(t){var n={};e.each(t,function(e,t){n[e]=t});return n});jQuery("#woocommerce-order-actions input, #woocommerce-order-actions a").click(function(){window.onbeforeunload=""});e("a.edit_address").click(function(t){e(this).hide();e(this).closest(".order_data_column").find("div.address").hide();e(this).closest(".order_data_column").find("div.edit_address").show();t.preventDefault()});e("#order_items_list").on("init_row","tr.item",function(){var t=e(this),n=t.find("input.quantity"),r=n.val(),i=t.find("input.line_subtotal").val(),s=t.find("input.line_total").val(),o=t.find("input.line_tax").val(),u=t.find("input.line_subtotal_tax").val();if(r){unit_subtotal=parseFloat(accounting.toFixed(i/r,woocommerce_admin_meta_boxes.rounding_precision));unit_subtotal_tax=parseFloat(accounting.toFixed(u/r,woocommerce_admin_meta_boxes.rounding_precision));unit_total=parseFloat(accounting.toFixed(s/r,woocommerce_admin_meta_boxes.rounding_precision));unit_total_tax=parseFloat(accounting.toFixed(o/r,woocommerce_admin_meta_boxes.rounding_precision))}else unit_subtotal=unit_subtotal_tax=unit_total=unit_total_tax=0;n.attr("data-o_qty",r);t.attr("data-unit_subtotal",unit_subtotal);t.attr("data-unit_subtotal_tax",unit_subtotal_tax);t.attr("data-unit_total",unit_total);t.attr("data-unit_total_tax",unit_total_tax)});e("#order_items_list tr.item").each(function(){e(this).trigger("init_row");e(this).find(".edit").hide()});e("#order_items_list").on("click","a.edit_order_item",function(){e(this).closest("tr").find(".view").hide();e(this).closest("tr").find(".edit").show();e(this).hide();return!1});e("#order_items_list").on("change","input.quantity",function(){var t=e(this).closest("tr.item"),n=e(this).val(),r=t.attr("data-unit_subtotal"),i=t.attr("data-unit_subtotal_tax"),s=t.attr("data-unit_total"),o=t.attr("data-unit_total_tax"),u=e(this).attr("data-o_qty"),a=parseFloat(accounting.formatNumber(r*n,woocommerce_admin_meta_boxes.rounding_precision,"")),f=parseFloat(accounting.formatNumber(i*n,woocommerce_admin_meta_boxes.rounding_precision,"")),l=parseFloat(accounting.formatNumber(s*n,woocommerce_admin_meta_boxes.rounding_precision,"")),c=parseFloat(accounting.formatNumber(o*n,woocommerce_admin_meta_boxes.rounding_precision,""));t.find("input.line_subtotal").val(a);t.find("input.line_total").val(l);t.find("input.line_subtotal_tax").val(f);t.find("input.line_tax").val(c);e(this).trigger("quantity_changed")});e("#order_items_list").on("change","input.line_subtotal",function(){var t=e(this).closest("tr.item"),n=t.find("input.quantity"),r=n.val(),i=r?accounting.toFixed(e(this).val()/r,woocommerce_admin_meta_boxes.rounding_precision):0;t.attr("data-unit_subtotal",i)});e("#order_items_list").on("change","input.line_total",function(){var t=e(this).closest("tr.item"),n=t.find("input.quantity"),r=n.val(),i=r?accounting.toFixed(e(this).val()/r,woocommerce_admin_meta_boxes.rounding_precision):0;t.attr("data-unit_total",i)});e("#order_items_list").on("change","input.line_subtotal_tax",function(){var t=e(this).closest("tr.item"),n=t.find("input.quantity"),r=n.val(),i=r?accounting.toFixed(e(this).val()/r,woocommerce_admin_meta_boxes.rounding_precision):0;t.attr("data-unit_subtotal_tax",i)});e("#order_items_list").on("change","input.line_tax",function(){var t=e(this).closest("tr.item"),n=t.find("input.quantity"),r=n.val(),i=r?accounting.toFixed(e(this).val()/r,woocommerce_admin_meta_boxes.rounding_precision):0;t.attr("data-unit_total_tax",i)});e("#woocommerce-order-totals").on("change input",".order_taxes_amount, .order_taxes_shipping_amount, .shipping_cost, #_order_discount",function(){var t=e(this),n=t.closest(".totals_group").find("input[type=number], .wc_input_decimal"),r=0;n.each(function(){e(this).val()&&(r+=parseFloat(e(this).val()))});if(t.is(".order_taxes_amount")||t.is(".order_taxes_shipping_amount"))r=round(r,woocommerce_admin_meta_boxes.currency_format_num_decimals,woocommerce_admin_meta_boxes.tax_rounding_mode);var i=accounting.formatMoney(r,{symbol:woocommerce_admin_meta_boxes.currency_format_symbol,decimal:woocommerce_admin_meta_boxes.currency_format_decimal_sep,thousand:woocommerce_admin_meta_boxes.currency_format_thousand_sep,precision:woocommerce_admin_meta_boxes.currency_format_num_decimals,format:woocommerce_admin_meta_boxes.currency_format});t.closest(".totals_group").find("span.inline_total").text(i)});e("span.inline_total").closest(".totals_group").find("input").change();e("button.calc_line_taxes").click(function(){e(".woocommerce_order_items_wrapper").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t=confirm(woocommerce_admin_meta_boxes.calc_line_taxes);if(t){var n=e("#order_items_list").find("tr.item, tr.fee"),r=e("#_shipping_country").val(),i=e("#_billing_country").val();if(r)var s=r,o=e("#_shipping_state").val(),u=e("#_shipping_postcode").val(),a=e("#_shipping_city").val();else if(i)var s=i,o=e("#_billing_state").val(),u=e("#_billing_postcode").val(),a=e("#_billing_city").val();else var s=woocommerce_admin_meta_boxes.base_country,o="",u="",a="";var f={};n.each(function(){var t=e(this),n=t.find("input.order_item_id").val(),r=t.find("input.line_subtotal").val(),i=t.find("input.line_total").val(),s=t.find("select.tax_class").val();f[n]={};f[n].line_subtotal=r;f[n].line_total=i;f[n].tax_class=s});order_shipping=0;e("#shipping_rows").find("input[type=number], .wc_input_decimal").each(function(){cost=e(this).val()||"0";cost=accounting.unformat(cost.replace(",","."));order_shipping+=parseFloat(cost)});var l={action:"woocommerce_calc_line_taxes",order_id:woocommerce_admin_meta_boxes.post_id,items:f,shipping:order_shipping,country:s,state:o,postcode:u,city:a,security:woocommerce_admin_meta_boxes.calc_totals_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,l,function(t){if(t){n.each(function(){var n=e(this),r=n.find("input.order_item_id").val();n.find(".edit_order_item").click();if(t.item_taxes[r]){n.find("input.line_tax").val(t.item_taxes[r].line_tax).change();n.find("input.line_subtotal_tax").val(t.item_taxes[r].line_subtotal_tax).change()}t.tax_row_html&&e("#tax_rows").empty().append(t.tax_row_html)});e("#tax_rows").find("input").change()}e(".woocommerce_order_items_wrapper").unblock()})}else e(".woocommerce_order_items_wrapper").unblock();return!1});e("button.calc_totals").click(function(){e("#woocommerce-order-totals").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t=confirm(woocommerce_admin_meta_boxes.calc_totals);if(t){var n=0,r=0,i=0,s=e("#_order_discount").val()||"0";s=accounting.unformat(s.replace(",","."));e("#shipping_rows").find("input[type=number], .wc_input_decimal").each(function(){cost=e(this).val()||"0";cost=accounting.unformat(cost.replace(",","."));i+=parseFloat(cost)});e("#tax_rows").find("input[type=number], .wc_input_decimal").each(function(){cost=e(this).val()||"0";cost=accounting.unformat(cost.replace(",","."));r+=parseFloat(cost)});e("#order_items_list tr.item, #order_items_list tr.fee").each(function(){line_total=e(this).find("input.line_total").val()||"0";n+=accounting.unformat(line_total.replace(",","."))});woocommerce_admin_meta_boxes.round_at_subtotal=="yes"&&(r=parseFloat(accounting.toFixed(r,woocommerce_admin_meta_boxes.rounding_precision)));e("#_order_total").val(parseFloat(accounting.toFixed(n+r+i-s,woocommerce_admin_meta_boxes.currency_format_num_decimals))).change()}e("#woocommerce-order-totals").unblock();return!1});e("#woocommerce-order-items button.add_order_item").click(function(){var t=e("select#add_item_id").val();if(t){count=t.length;e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.each(t,function(t,n){var r={action:"woocommerce_add_order_item",item_to_add:n,order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,r,function(t){e("table.woocommerce_order_items tbody#order_items_list").append(t);if(!--count){e("select#add_item_id, #add_item_id_chosen .chosen-choices").css("border-color","").val("");jQuery(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200});e("select#add_item_id").trigger("chosen:updated");e("table.woocommerce_order_items").unblock()}e("#order_items_list tr.new_row").trigger("init_row").removeClass("new_row")})})}else e("select#add_item_id, #add_item_id_chosen .chosen-choices").css("border-color","red");return!1});e("#woocommerce-order-items button.add_order_fee").click(function(){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t={action:"woocommerce_add_order_fee",order_id:woocommerce_admin_meta_boxes.post_id,security:woocommerce_admin_meta_boxes.order_item_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,t,function(t){e("table.woocommerce_order_items tbody#order_items_list").append(t);e("table.woocommerce_order_items").unblock()});return!1});e("#order_items_list").on("click","button.add_order_item_meta",function(){var t=e(this),n=t.closest("tr.item"),r={order_item_id:n.attr("data-order_item_id"),action:"woocommerce_add_order_item_meta",security:woocommerce_admin_meta_boxes.order_item_nonce};e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(t){n.find("tbody.meta_items").append(t);e("table.woocommerce_order_items").unblock()}});return!1});e("#order_items_list").on("click","button.remove_order_item_meta",function(){var t=confirm(woocommerce_admin_meta_boxes.remove_item_meta);if(t){var n=e(this).closest("tr"),r={meta_id:n.attr("data-meta_id"),action:"woocommerce_remove_order_item_meta",security:woocommerce_admin_meta_boxes.order_item_nonce};e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(t){n.hide();e("table.woocommerce_order_items").unblock()}})}return!1});e("#woocommerce-order-items").on("click","input.check-column",function(){e(this).is(":checked")?e("#woocommerce-order-items").find(".check-column input").attr("checked","checked"):e("#woocommerce-order-items").find(".check-column input").removeAttr("checked")});e("#woocommerce-order-items").on("click",".do_bulk_action",function(){var t=e(this).closest(".bulk_actions").find("select").val(),n=e("#woocommerce-order-items").find(".check-column input:checked"),r=[];e(n).each(function(){var t=e(this).closest("tr.item, tr.fee");r.push(t.attr("data-order_item_id"))});if(r.length==0){alert(woocommerce_admin_meta_boxes.i18n_select_items);return}if(t=="delete"){var i=confirm(woocommerce_admin_meta_boxes.remove_item_notice);if(i){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var s={order_item_ids:r,action:"woocommerce_remove_order_item",security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:s,type:"POST",success:function(t){e(n).each(function(){e(this).closest("tr.item, tr.fee").remove()});e("table.woocommerce_order_items").unblock()}})}}else if(t=="reduce_stock"){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var o={};e(n).each(function(){var t=e(this).closest("tr.item, tr.fee"),n=t.find("input.quantity");o[t.attr("data-order_item_id")]=n.val()});var s={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:r,order_item_qty:o,action:"woocommerce_reduce_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:s,type:"POST",success:function(t){alert(t);e("table.woocommerce_order_items").unblock()}})}else if(t=="increase_stock"){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var o={};e(n).each(function(){var t=e(this).closest("tr.item, tr.fee"),n=t.find("input.quantity");o[t.attr("data-order_item_id")]=n.val()});var s={order_id:woocommerce_admin_meta_boxes.post_id,order_item_ids:r,order_item_qty:o,action:"woocommerce_increase_order_item_stock",security:woocommerce_admin_meta_boxes.order_item_nonce};e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:s,type:"POST",success:function(t){alert(t);e("table.woocommerce_order_items").unblock()}})}return!1});e("button.load_customer_billing").click(function(){var t=confirm(woocommerce_admin_meta_boxes.load_billing);if(t){var n=e("#customer_user").val();if(!n){alert(woocommerce_admin_meta_boxes.no_customer_selected);return!1}var r={user_id:n,type_to_load:"billing",action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};e(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(t){var n=t;if(n){e("input#_billing_first_name").val(n.billing_first_name);e("input#_billing_last_name").val(n.billing_last_name);e("input#_billing_company").val(n.billing_company);e("input#_billing_address_1").val(n.billing_address_1);e("input#_billing_address_2").val(n.billing_address_2);e("input#_billing_city").val(n.billing_city);e("input#_billing_postcode").val(n.billing_postcode);e("#_billing_country").val(n.billing_country);e("input#_billing_state").val(n.billing_state);e("input#_billing_email").val(n.billing_email);e("input#_billing_phone").val(n.billing_phone)}e(".edit_address").unblock()}})}return!1});e("button.load_customer_shipping").click(function(){var t=confirm(woocommerce_admin_meta_boxes.load_shipping);if(t){var n=e("#customer_user").val();if(!n){alert(woocommerce_admin_meta_boxes.no_customer_selected);return!1}var r={user_id:n,type_to_load:"shipping",action:"woocommerce_get_customer_details",security:woocommerce_admin_meta_boxes.get_customer_details_nonce};e(this).closest(".edit_address").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e.ajax({url:woocommerce_admin_meta_boxes.ajax_url,data:r,type:"POST",success:function(t){var n=t;if(n){e("input#_shipping_first_name").val(n.shipping_first_name);e("input#_shipping_last_name").val(n.shipping_last_name);e("input#_shipping_company").val(n.shipping_company);e("input#_shipping_address_1").val(n.shipping_address_1);e("input#_shipping_address_2").val(n.shipping_address_2);e("input#_shipping_city").val(n.shipping_city);e("input#_shipping_postcode").val(n.shipping_postcode);e("#_shipping_country").val(n.shipping_country);e("input#_shipping_state").val(n.shipping_state)}e(".edit_address").unblock()}})}return!1});e("button.billing-same-as-shipping").click(function(){var t=confirm(woocommerce_admin_meta_boxes.copy_billing);if(t){e("input#_shipping_first_name").val(e("input#_billing_first_name").val());e("input#_shipping_last_name").val(e("input#_billing_last_name").val());e("input#_shipping_company").val(e("input#_billing_company").val());e("input#_shipping_address_1").val(e("input#_billing_address_1").val());e("input#_shipping_address_2").val(e("input#_billing_address_2").val());e("input#_shipping_city").val(e("input#_billing_city").val());e("input#_shipping_postcode").val(e("input#_billing_postcode").val());e("#_shipping_country").val(e("#_billing_country").val());e("input#_shipping_state").val(e("input#_billing_state").val())}return!1});e(".totals_group").on("click","a.add_total_row",function(){e(this).closest(".totals_group").find(".total_rows").append(e(this).data("row"));return!1});e(".total_rows").on("click","a.delete_total_row",function(){$row=e(this).closest(".total_row");var t=$row.attr("data-order_item_id");t?$row.append('').hide():$row.remove();return!1});e("select#product-type").change(function(){var n=e(this).val();if(n=="variable"){e("input#_manage_stock").change();e("input#_downloadable").prop("checked",!1);e("input#_virtual").removeAttr("checked")}else if(n=="grouped"){e("input#_downloadable").prop("checked",!1);e("input#_virtual").removeAttr("checked")}else if(n=="external"){e("input#_downloadable").prop("checked",!1);e("input#_virtual").removeAttr("checked")}t();e("ul.wc-tabs li:visible").eq(0).find("a").click();e("body").trigger("woocommerce-product-type-change",n,e(this))}).change();e("ul.wc-tabs li:visible").eq(0).find("a").click();e("input#_downloadable, input#_virtual").change(function(){t()});e(".sale_price_dates_fields").each(function(){var t=e(this),n=!1,r=t.closest("div, table");t.find("input").each(function(){e(this).val()!=""&&(n=!0)});if(n){r.find(".sale_schedule").hide();r.find(".sale_price_dates_fields").show()}else{r.find(".sale_schedule").show();r.find(".sale_price_dates_fields").hide()}});e("#woocommerce-product-data").on("click",".sale_schedule",function(){var t=e(this).closest("div, table");e(this).hide();t.find(".cancel_sale_schedule").show();t.find(".sale_price_dates_fields").show();return!1});e("#woocommerce-product-data").on("click",".cancel_sale_schedule",function(){var t=e(this).closest("div, table");e(this).hide();t.find(".sale_schedule").show();t.find(".sale_price_dates_fields").hide();t.find(".sale_price_dates_fields").find("input").val("");return!1});e(".downloadable_files").on("click","a.insert",function(){e(this).closest(".downloadable_files").find("tbody").append(e(this).data("row"));return!1});e(".downloadable_files").on("click","a.delete",function(){e(this).closest("tr").remove();return!1});e("input#_manage_stock").change(function(){e(this).is(":checked")?e("div.stock_fields").show():e("div.stock_fields").hide()}).change();var n=e(".sale_price_dates_fields input").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_admin_meta_boxes.calendar_image,buttonImageOnly:!0,onSelect:function(t){var r=e(this).is("#_sale_price_dates_from, .sale_price_dates_from")?"minDate":"maxDate",i=e(this).data("datepicker"),s=e.datepicker.parseDate(i.settings.dateFormat||e.datepicker._defaults.dateFormat,t,i.settings);n.not(this).datepicker("option",r,s)}});e(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0,showOn:"button",buttonImage:woocommerce_admin_meta_boxes.calendar_image,buttonImageOnly:!0});e(".date-picker-field").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:!0});jQuery(".wc-metaboxes-wrapper").on("click",".wc-metabox h3",function(t){if(e(t.target).filter(":input, option").length)return;jQuery(this).next(".wc-metabox-content").toggle()}).on("click",".expand_all",function(e){jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").show();return!1}).on("click",".close_all",function(e){jQuery(this).closest(".wc-metaboxes-wrapper").find(".wc-metabox > table").hide();return!1});jQuery(".wc-metabox.closed").each(function(){jQuery(this).find(".wc-metabox-content").hide()});e(".woocommerce_attributes select.multiselect").chosen();var r=e(".woocommerce_attributes").find(".woocommerce_attribute").get();r.sort(function(t,n){var r=parseInt(e(t).attr("rel")),i=parseInt(e(n).attr("rel"));return ri?1:0});e(r).each(function(t,n){e(".woocommerce_attributes").append(n)});e("button.add_attribute").on("click",function(){var t=e(".woocommerce_attributes .woocommerce_attribute").size(),n=e("select.attribute_taxonomy").val();if(!n){var r=e("select#product-type").val();r!="variable"?enable_variation='style="display:none;"':enable_variation="";e(".woocommerce_attributes").append('")}else{var s=e(".woocommerce_attributes .woocommerce_attribute."+n);e(".woocommerce_attributes").append(e(s));e(s).show().find(".woocommerce_attribute_data").show();i()}e("select.attribute_taxonomy").val("")});e(".woocommerce_attributes").on("blur","input.attribute_name",function(){e(this).closest(".woocommerce_attribute").find("strong.attribute_name").text(e(this).val())});e(".woocommerce_attributes").on("click","button.select_all_attributes",function(){e(this).closest("td").find("select option").attr("selected","selected");e(this).closest("td").find("select").trigger("chosen:updated");return!1});e(".woocommerce_attributes").on("click","button.select_no_attributes",function(){e(this).closest("td").find("select option").removeAttr("selected");e(this).closest("td").find("select").trigger("chosen:updated");return!1});e(".woocommerce_attributes").on("click","button.remove_row",function(){var t=confirm(woocommerce_admin_meta_boxes.remove_attribute);if(t){var n=e(this).parent().parent();if(n.is(".taxonomy")){n.find("select, input[type=text]").val("");n.hide()}else{n.find("select, input[type=text]").val("");n.hide();i()}}return!1});e(".woocommerce_attributes").sortable({items:".woocommerce_attribute",cursor:"move",axis:"y",handle:"h3",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");i()}});e(".woocommerce_attributes").on("click","button.add_new_attribute",function(){e(".woocommerce_attributes").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t=e(this).attr("data-attribute"),n=e(this).closest(".woocommerce_attribute_data"),r=prompt(woocommerce_admin_meta_boxes.new_attribute_prompt);if(r){var i={action:"woocommerce_add_new_attribute",taxonomy:t,term:r,security:woocommerce_admin_meta_boxes.add_attribute_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,i,function(t){if(t.error)alert(t.error);else if(t.slug){n.find("select.attribute_values").append('");n.find("select.attribute_values").trigger("chosen:updated")}e(".woocommerce_attributes").unblock()})}else e(".woocommerce_attributes").unblock();return!1});e(".save_attributes").on("click",function(){e(".woocommerce_attributes").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});var t={post_id:woocommerce_admin_meta_boxes.post_id,data:e(".woocommerce_attributes").find("input, select, textarea").serialize(),action:"woocommerce_save_attributes",security:woocommerce_admin_meta_boxes.save_attributes_nonce};e.post(woocommerce_admin_meta_boxes.ajax_url,t,function(t){var n=window.location.toString();n=n.replace("post-new.php?","post.php?post="+woocommerce_admin_meta_boxes.post_id+"&action=edit&");e("#variable_product_options").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_admin_meta_boxes.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:.6}});e("#variable_product_options").load(n+" #variable_product_options_inner",function(){e("#variable_product_options").unblock()});e(".woocommerce_attributes").unblock()})});var s,o;jQuery(document).on("click",".upload_file_button",function(t){var n=e(this);o=n.closest("tr").find("td.file_url input");t.preventDefault();if(s){s.open();return}var r=[new wp.media.controller.Library({library:wp.media.query(),multiple:!0,title:n.data("choose"),priority:20,filterable:"uploaded"})];s=wp.media.frames.downloadable_file=wp.media({title:n.data("choose"),library:{type:""},button:{text:n.data("update")},multiple:!0,states:r});s.on("select",function(){var e="",t=s.state().get("selection");t.map(function(t){t=t.toJSON();t.url&&(e=t.url)});o.val(e)});s.on("ready",function(){s.uploader.options.uploader.params={type:"downloadable_product"}});s.open()});jQuery(".downloadable_files tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:"td.sort",scrollSensitivity:40,forcePlaceholderSize:!0,helper:"clone",opacity:.65})});
\ No newline at end of file
diff --git a/assets/js/admin/round.js b/assets/js/admin/round.js
new file mode 100644
index 00000000000..819a6518562
--- /dev/null
+++ b/assets/js/admin/round.js
@@ -0,0 +1,55 @@
+function round (value, precision, mode) {
+ // http://kevin.vanzonneveld.net
+ // + original by: Philip Peterson
+ // + revised by: Onno Marsman
+ // + input by: Greenseed
+ // + revised by: T.Wild
+ // + input by: meo
+ // + input by: William
+ // + bugfixed by: Brett Zamir (http://brett-zamir.me)
+ // + input by: Josep Sanz (http://www.ws3.es/)
+ // + revised by: Rafał Kukawski (http://blog.kukawski.pl/)
+ // % note 1: Great work. Ideas for improvement:
+ // % note 1: - code more compliant with developer guidelines
+ // % note 1: - for implementing PHP constant arguments look at
+ // % note 1: the pathinfo() function, it offers the greatest
+ // % note 1: flexibility & compatibility possible
+ // * example 1: round(1241757, -3);
+ // * returns 1: 1242000
+ // * example 2: round(3.6);
+ // * returns 2: 4
+ // * example 3: round(2.835, 2);
+ // * returns 3: 2.84
+ // * example 4: round(1.1749999999999, 2);
+ // * returns 4: 1.17
+ // * example 5: round(58551.799999999996, 2);
+ // * returns 5: 58551.8
+ var m, f, isHalf, sgn; // helper variables
+ precision |= 0; // making sure precision is integer
+ m = Math.pow(10, precision);
+ value *= m;
+ sgn = (value > 0) | -(value < 0); // sign of the number
+ isHalf = value % 1 === 0.5 * sgn;
+ f = Math.floor(value);
+
+ if (isHalf) {
+ switch (mode) {
+ case '2':
+ case 'PHP_ROUND_HALF_DOWN':
+ value = f + (sgn < 0); // rounds .5 toward zero
+ break;
+ case '3':
+ case 'PHP_ROUND_HALF_EVEN':
+ value = f + (f % 2 * sgn); // rouds .5 towards the next even integer
+ break;
+ case '4':
+ case 'PHP_ROUND_HALF_ODD':
+ value = f + !(f % 2); // rounds .5 towards the next odd integer
+ break;
+ default:
+ value = f + (sgn > 0); // rounds .5 away from zero
+ }
+ }
+
+ return (isHalf ? value : Math.round(value)) / m;
+}
\ No newline at end of file
diff --git a/assets/js/admin/round.min.js b/assets/js/admin/round.min.js
new file mode 100644
index 00000000000..35635ff19a1
--- /dev/null
+++ b/assets/js/admin/round.min.js
@@ -0,0 +1 @@
+function round(e,t,n){var r,i,s,o;t|=0;r=Math.pow(10,t);e*=r;o=e>0|-(e<0);s=e%1===.5*o;i=Math.floor(e);if(s)switch(n){case"2":case"PHP_ROUND_HALF_DOWN":e=i+(o<0);break;case"3":case"PHP_ROUND_HALF_EVEN":e=i+i%2*o;break;case"4":case"PHP_ROUND_HALF_ODD":e=i+!(i%2);break;default:e=i+(o>0)}return(s?e:Math.round(e))/r};
\ No newline at end of file
diff --git a/includes/abstracts/abstract-wc-product.php b/includes/abstracts/abstract-wc-product.php
index d416f1266ed..e9e68987dd2 100644
--- a/includes/abstracts/abstract-wc-product.php
+++ b/includes/abstracts/abstract-wc-product.php
@@ -769,7 +769,7 @@ class WC_Product {
$tax_rates = $_tax->get_rates( $this->get_tax_class() );
$taxes = $_tax->calc_tax( $price * $qty, $tax_rates, false );
$tax_amount = $_tax->get_tax_total( $taxes );
- $price = round( $price * $qty + $tax_amount, 2 );
+ $price = round( $price * $qty + $tax_amount, absint( get_option( 'woocommerce_price_num_decimals' ) ) );
} else {
@@ -780,13 +780,13 @@ class WC_Product {
$base_taxes = $_tax->calc_tax( $price * $qty, $base_tax_rates, true );
$base_tax_amount = array_sum( $base_taxes );
- $price = round( $price * $qty - $base_tax_amount, 2 );
+ $price = round( $price * $qty - $base_tax_amount, absint( get_option( 'woocommerce_price_num_decimals' ) ) );
} elseif ( $tax_rates !== $base_tax_rates ) {
$base_taxes = $_tax->calc_tax( $price * $qty, $base_tax_rates, true );
$modded_taxes = $_tax->calc_tax( ( $price * $qty ) - array_sum( $base_taxes ), $tax_rates, false );
- $price = round( ( $price * $qty ) - array_sum( $base_taxes ) + array_sum( $modded_taxes ), 2 );
+ $price = round( ( $price * $qty ) - array_sum( $base_taxes ) + array_sum( $modded_taxes ), absint( get_option( 'woocommerce_price_num_decimals' ) ) );
} else {
diff --git a/includes/admin/class-wc-admin-assets.php b/includes/admin/class-wc-admin-assets.php
index c184393ee38..4ed4417e42d 100644
--- a/includes/admin/class-wc-admin-assets.php
+++ b/includes/admin/class-wc-admin-assets.php
@@ -76,7 +76,9 @@ class WC_Admin_Assets {
wp_register_script( 'accounting', $woocommerce->plugin_url() . '/assets/js/admin/accounting' . $suffix . '.js', array( 'jquery' ), '1.3.2' );
- wp_register_script( 'woocommerce_admin_meta_boxes', $woocommerce->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting' ), $woocommerce->version );
+ wp_register_script( 'round', $woocommerce->plugin_url() . '/assets/js/admin/round' . $suffix . '.js', array( 'jquery' ), '1.0.0' );
+
+ wp_register_script( 'woocommerce_admin_meta_boxes', $woocommerce->plugin_url() . '/assets/js/admin/meta-boxes' . $suffix . '.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'accounting', 'round' ), $woocommerce->version );
wp_register_script( 'woocommerce_admin_meta_boxes_variations', $woocommerce->plugin_url() . '/assets/js/admin/meta-boxes-variations' . $suffix . '.js', array( 'jquery', 'jquery-ui-sortable' ), $woocommerce->version );
@@ -160,6 +162,8 @@ class WC_Admin_Assets {
'currency_format_decimal_sep' => esc_attr( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ) ),
'currency_format_thousand_sep' => esc_attr( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ) ),
'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS
+ 'rounding_precision' => WC_ROUNDING_PRECISION,
+ 'tax_rounding_mode' => WC_TAX_ROUNDING_MODE,
'product_types' => array_map( 'sanitize_title', get_terms( 'product_type', array( 'hide_empty' => false, 'fields' => 'names' ) ) ),
'default_attribute_visibility' => apply_filters( 'default_attribute_visibility', false ),
'default_attribute_variation' => apply_filters( 'default_attribute_variation', false ),
diff --git a/includes/admin/class-wc-admin-notices.php b/includes/admin/class-wc-admin-notices.php
index c04d41f86a7..243df2695c3 100644
--- a/includes/admin/class-wc-admin-notices.php
+++ b/includes/admin/class-wc-admin-notices.php
@@ -29,7 +29,7 @@ class WC_Admin_Notices {
*/
public function add_notices() {
if ( get_option( '_wc_needs_update' ) == 1 || get_option( '_wc_needs_pages' ) == 1 ) {
- wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WOOCOMMERCE_PLUGIN_FILE ) );
+ wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'install_notice' ) );
}
@@ -43,7 +43,7 @@ class WC_Admin_Notices {
}
if ( get_option( 'woocommerce_theme_support_check' ) !== $template ) {
- wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WOOCOMMERCE_PLUGIN_FILE ) );
+ wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
}
}
diff --git a/includes/admin/class-wc-admin-welcome.php b/includes/admin/class-wc-admin-welcome.php
index 3b820b4b376..3689ad3ab75 100644
--- a/includes/admin/class-wc-admin-welcome.php
+++ b/includes/admin/class-wc-admin-welcome.php
@@ -64,7 +64,7 @@ class WC_Admin_Welcome {
* @return void
*/
public function admin_css() {
- wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WOOCOMMERCE_PLUGIN_FILE ) );
+ wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ) );
}
/**
diff --git a/includes/admin/post-types/meta-boxes/class-wc-meta-box-order-totals.php b/includes/admin/post-types/meta-boxes/class-wc-meta-box-order-totals.php
index ffa97f46f5e..9ddbb9f2535 100644
--- a/includes/admin/post-types/meta-boxes/class-wc-meta-box-order-totals.php
+++ b/includes/admin/post-types/meta-boxes/class-wc-meta-box-order-totals.php
@@ -269,8 +269,8 @@ class WC_Meta_Box_Order_Totals {
}
// Update totals
- update_post_meta( $post_id, '_order_tax', woocommerce_format_decimal( $total_tax, false ) );
- update_post_meta( $post_id, '_order_shipping_tax', woocommerce_format_decimal( $total_shipping_tax, false ) );
+ 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 ) );
diff --git a/includes/admin/post-types/meta-boxes/class-wc-meta-box-product-data.php b/includes/admin/post-types/meta-boxes/class-wc-meta-box-product-data.php
index edb6a7ff317..b89bb2223b0 100644
--- a/includes/admin/post-types/meta-boxes/class-wc-meta-box-product-data.php
+++ b/includes/admin/post-types/meta-boxes/class-wc-meta-box-product-data.php
@@ -469,7 +469,7 @@ class WC_Meta_Box_Product_Data {
$values = array();
foreach ( $post_terms as $term )
$values[] = $term->name;
- echo esc_attr( implode( ' ' . WOOCOMMERCE_DELIMITER . ' ', $values ) );
+ echo esc_attr( implode( ' ' . WC_DELIMITER . ' ', $values ) );
}
?>" placeholder="" />
@@ -898,7 +898,7 @@ class WC_Meta_Box_Product_Data {
} else {
- $options = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
+ $options = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
foreach ( $options as $option )
echo '';
@@ -1036,7 +1036,7 @@ class WC_Meta_Box_Product_Data {
// Text based attributes - Posted values are term names - don't change to slugs
} else {
- $values = array_map( 'stripslashes', array_map( 'strip_tags', explode( WOOCOMMERCE_DELIMITER, $attribute_values[ $i ] ) ) );
+ $values = array_map( 'stripslashes', array_map( 'strip_tags', explode( WC_DELIMITER, $attribute_values[ $i ] ) ) );
}
// Remove empty items in the array
@@ -1065,7 +1065,7 @@ class WC_Meta_Box_Product_Data {
} elseif ( isset( $attribute_values[ $i ] ) ) {
// Text based, separate by pipe
- $values = implode( ' ' . WOOCOMMERCE_DELIMITER . ' ', array_map( 'woocommerce_clean', explode( WOOCOMMERCE_DELIMITER, $attribute_values[ $i ] ) ) );
+ $values = implode( ' ' . WC_DELIMITER . ' ', array_map( 'woocommerce_clean', explode( WC_DELIMITER, $attribute_values[ $i ] ) ) );
// Custom attribute - Add attribute to array and set the values
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
diff --git a/includes/admin/post-types/meta-boxes/views/html-order-fee.php b/includes/admin/post-types/meta-boxes/views/html-order-fee.php
index dc9b29c496b..293b8e6a2de 100644
--- a/includes/admin/post-types/meta-boxes/views/html-order-fee.php
+++ b/includes/admin/post-types/meta-boxes/views/html-order-fee.php
@@ -56,7 +56,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-
+
@@ -67,7 +67,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-
+
diff --git a/includes/admin/post-types/meta-boxes/views/html-order-item.php b/includes/admin/post-types/meta-boxes/views/html-order-item.php
index caf2b6408af..1cdced4a4d8 100644
--- a/includes/admin/post-types/meta-boxes/views/html-order-item.php
+++ b/includes/admin/post-types/meta-boxes/views/html-order-item.php
@@ -176,9 +176,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
' . woocommerce_price( $item['line_subtotal_tax'] ) . ' ';
+ if ( isset( $item['line_subtotal_tax'] ) && $item['line_subtotal_tax'] != $item['line_tax'] ) echo '' . woocommerce_price( woocommerce_round_tax_total( $item['line_subtotal_tax'] ) ) . ' ';
- echo woocommerce_price( $item['line_tax'] );
+ echo woocommerce_price( woocommerce_round_tax_total( $item['line_tax'] ) );
}
?>
diff --git a/includes/admin/post-types/meta-boxes/views/html-variation-admin.php b/includes/admin/post-types/meta-boxes/views/html-variation-admin.php
index 166c506f7ab..37b08635cdd 100644
--- a/includes/admin/post-types/meta-boxes/views/html-variation-admin.php
+++ b/includes/admin/post-types/meta-boxes/views/html-variation-admin.php
@@ -30,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
} else {
- $options = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
+ $options = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
foreach ( $options as $option ) {
echo ' ';
diff --git a/includes/admin/reports/class-wc-report-taxes-by-code.php b/includes/admin/reports/class-wc-report-taxes-by-code.php
index fc267a8155c..f0e326298c2 100644
--- a/includes/admin/reports/class-wc-report-taxes-by-code.php
+++ b/includes/admin/reports/class-wc-report-taxes-by-code.php
@@ -72,13 +72,13 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
'tax_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'tax',
- 'function' => 'SUM',
+ 'function' => '',
'name' => 'tax_amount'
),
'shipping_tax_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'tax',
- 'function' => 'SUM',
+ 'function' => '',
'name' => 'shipping_tax_amount'
),
'rate_id' => array(
@@ -86,13 +86,7 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
'order_item_type' => 'tax',
'function' => '',
'name' => 'rate_id'
- ),
- 'ID' => array(
- 'type' => 'post_data',
- 'function' => 'COUNT',
- 'name' => 'total_orders',
- 'distinct' => true,
- ),
+ )
),
'where' => array(
array(
@@ -106,7 +100,6 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
'operator' => '!='
)
),
- 'group_by' => 'tax_rate',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true
@@ -127,15 +120,32 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
|
- |
- |
- |
+ |
+ |
+ |
get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $tax_row->rate_id ) );
+ if ( ! isset( $grouped_tax_tows[ $tax_row->rate_id ] ) ) {
+ $grouped_tax_tows[ $tax_row->rate_id ] = (object) array(
+ 'tax_rate' => $tax_row->tax_rate,
+ 'total_orders' => 0,
+ 'tax_amount' => 0,
+ 'shipping_tax_amount' => 0
+ );
+ }
+
+ $grouped_tax_tows[ $tax_row->rate_id ]->total_orders ++;
+ $grouped_tax_tows[ $tax_row->rate_id ]->tax_amount += woocommerce_round_tax_total( $tax_row->tax_amount );
+ $grouped_tax_tows[ $tax_row->rate_id ]->shipping_tax_amount += woocommerce_round_tax_total( $tax_row->shipping_tax_amount );
+ }
+
+ foreach ( $grouped_tax_tows as $rate_id => $tax_row ) {
+ $rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %d;", $rate_id ) );
?>
tax_rate; ?> |
diff --git a/includes/class-wc-cart.php b/includes/class-wc-cart.php
index c8c680188f4..f50102ae633 100644
--- a/includes/class-wc-cart.php
+++ b/includes/class-wc-cart.php
@@ -677,21 +677,6 @@ class WC_Cart {
return apply_filters( 'woocommerce_cart_get_taxes', $taxes, $this );
}
- /**
- * Returns the cart and shipping taxes, merged & formatted.
- *
- * @return array merged taxes
- */
- public function get_formatted_taxes() {
- $taxes = $this->get_taxes();
-
- foreach ( $taxes as $key => $tax )
- if ( is_numeric( $tax ) )
- $taxes[ $key ] = woocommerce_price( $tax );
-
- return apply_filters( 'woocommerce_cart_formatted_taxes', $taxes, $this );
- }
-
/**
* Get taxes, merged by code, formatted ready for output.
*
@@ -715,7 +700,7 @@ class WC_Cart {
$tax_totals[ $code ]->is_compound = $this->tax->is_compound( $key );
$tax_totals[ $code ]->label = $this->tax->get_rate_label( $key );
$tax_totals[ $code ]->amount += $tax;
- $tax_totals[ $code ]->formatted_amount = woocommerce_price( $tax_totals[ $code ]->amount );
+ $tax_totals[ $code ]->formatted_amount = woocommerce_price( woocommerce_round_tax_total( $tax_totals[ $code ]->amount ) );
}
return apply_filters( 'woocommerce_cart_tax_totals', $tax_totals, $this );
@@ -967,260 +952,227 @@ class WC_Cart {
return;
}
- // Get count of all items + weights + subtotal (we may need this for discounts)
- $subtotal = 0;
- $subtotal_tax = 0;
$tax_rates = array();
+ $shop_tax_rates = array();
+ /**
+ * Calculate subtotals for items. This is done first so that discount logic can use the values.
+ */
foreach ( $this->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
// Count items + weight
- $this->cart_contents_weight = $this->cart_contents_weight + ( $_product->get_weight() * $values['quantity'] );
- $this->cart_contents_count = $this->cart_contents_count + $values['quantity'];
+ $this->cart_contents_weight += $_product->get_weight() * $values['quantity'];
+ $this->cart_contents_count += $values['quantity'];
- // Line price
- $line_price = $_product->get_price() * $values['quantity'];
+ // Prices
+ $base_price = $_product->get_price();
+ $line_price = $_product->get_price() * $values['quantity'];
+ /**
+ * No tax to calculate
+ */
if ( ! $_product->is_taxable() ) {
- $subtotal += $line_price;
- } else {
+ // Subtotal is the undiscounted price
+ $this->subtotal += $line_price;
+ $this->subtotal_ex_tax += $line_price;
+
+ /**
+ * Prices include tax
+ *
+ * To prevent rounding issues we need to work with the inclusive price where possible
+ * otherwise we'll see errors such as when working with a 9.99 inc price, 20% VAT which would
+ * be 8.325 leading to totals being 1p off
+ *
+ * Pre tax coupons come off the price the customer thinks they are paying - tax is calculated
+ * afterwards.
+ *
+ * e.g. $100 bike with $10 coupon = customer pays $90 and tax worked backwards from that
+ */
+ } elseif ( $this->prices_include_tax ) {
+
// Get base tax rates
if ( empty( $shop_tax_rates[ $_product->tax_class ] ) )
$shop_tax_rates[ $_product->tax_class ] = $this->tax->get_shop_base_rate( $_product->tax_class );
- $base_tax_rates = $shop_tax_rates[ $_product->tax_class ];
-
// Get item tax rates
if ( empty( $tax_rates[ $_product->get_tax_class() ] ) )
$tax_rates[ $_product->get_tax_class() ] = $this->tax->get_rates( $_product->get_tax_class() );
+ $base_tax_rates = $shop_tax_rates[ $_product->tax_class ];
$item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
- if ( $this->prices_include_tax ) {
+ /**
+ * ADJUST TAX - Calculations when base tax is not equal to the item tax
+ */
+ if ( $item_tax_rates !== $base_tax_rates ) {
- // ADJUST BASE if tax rate is different (different region or modified tax class)
- if ( $item_tax_rates !== $base_tax_rates ) {
- // Work out a new base price without the shop's base tax
- $line_tax = array_sum( $this->tax->calc_tax( $line_price, $base_tax_rates, true ) );
-
- // Now we have a new item price (excluding TAX)
- $line_price = $this->tax->round( $line_price - $line_tax );
-
- // Now add taxes for the users location
- $line_tax = array_sum( $this->tax->calc_tax( $line_price, $item_tax_rates, false ) );
- $line_tax = $this->round_at_subtotal ? $line_tax : $this->tax->round( $line_tax );
-
- // Add to main subtotal
- $subtotal += $line_price;
- $subtotal_tax += $line_tax;
- } else {
- // Calc tax normally
- $line_tax = array_sum( $this->tax->calc_tax( $line_price, $item_tax_rates, true ) );
- $line_tax = $this->round_at_subtotal ? $line_tax : $this->tax->round( $line_tax );
-
- // Add to main subtotal
- $subtotal += $line_price - $line_tax;
- $subtotal_tax += $line_tax;
- }
+ // Work out a new base price without the shop's base tax
+ $taxes = $this->tax->calc_tax( $line_price, $base_tax_rates, true, true );
+
+ // Now we have a new item price (excluding TAX)
+ $line_subtotal = $line_price - array_sum( $taxes );
+
+ // Now add modifed taxes
+ $tax_result = $this->tax->calc_tax( $line_subtotal, $item_tax_rates );
+ $line_subtotal_tax = array_sum( $taxes );
+ /**
+ * Regular tax calculation (customer inside base and the tax class is unmodified
+ */
} else {
- if ( $_product->is_taxable() ) {
- $taxes = $this->tax->calc_tax( $line_price, $item_tax_rates, false );
- $line_tax = $this->round_at_subtotal ? array_sum( $taxes ) : $this->tax->get_tax_total( $taxes );
- $subtotal_tax += $line_tax;
- }
-
- $subtotal += $line_price;
+ // Calc tax normally
+ $taxes = $this->tax->calc_tax( $line_price, $item_tax_rates, true );
+ $line_subtotal_tax = array_sum( $taxes );
+ $line_subtotal = $line_price - array_sum( $taxes );
}
- }
-
- }
-
- $this->subtotal = $subtotal + $subtotal_tax;
- $this->subtotal_ex_tax = $subtotal;
-
- // Now calc the main totals, including discounts
- if ( $this->prices_include_tax ) {
-
/**
- * Calculate totals for items
+ * Prices exclude tax
+ *
+ * This calculation is simpler - work with the base, untaxed price.
*/
- foreach ( $this->get_cart() as $cart_item_key => $values ) {
+ } else {
+
+ // Get item tax rates
+ if ( empty( $tax_rates[ $_product->get_tax_class() ] ) )
+ $tax_rates[ $_product->get_tax_class() ] = $this->tax->get_rates( $_product->get_tax_class() );
- /**
- * Prices include tax
- *
- * To prevent rounding issues we need to work with the inclusive price where possible
- * otherwise we'll see errors such as when working with a 9.99 inc price, 20% VAT which would
- * be 8.325 leading to totals being 1p off
- *
- * Pre tax coupons come off the price the customer thinks they are paying - tax is calculated
- * afterwards.
- *
- * e.g. $100 bike with $10 coupon = customer pays $90 and tax worked backwards from that
- *
- * Used this excellent article for reference:
- * http://developer.practicalecommerce.com/articles/1473-Coding-for-Tax-Calculations-Everything-You-Never-Wanted-to-Know-Part-2
- */
- $_product = $values['data'];
+ $item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
- // Prices
- $base_price = $_product->get_price();
- $line_price = $_product->get_price() * $values['quantity'];
-
- // Base Price Adjustment
- if ( ! $_product->is_taxable() ) {
-
- // Discounted Price (price with any pre-tax discounts applied)
- $discounted_price = $this->get_discounted_price( $values, $base_price, true );
- $discounted_tax_amount = 0;
- $tax_amount = 0;
- $line_subtotal_tax = 0;
- $line_subtotal = $line_price;
-
- } else {
-
- // Get base tax rates
- if ( empty( $shop_tax_rates[ $_product->tax_class ] ) )
- $shop_tax_rates[ $_product->tax_class ] = $this->tax->get_shop_base_rate( $_product->tax_class );
-
- $base_tax_rates = $shop_tax_rates[ $_product->tax_class ];
-
- // Get item tax rates
- if ( empty( $tax_rates[ $_product->get_tax_class() ] ) )
- $tax_rates[ $_product->get_tax_class() ] = $this->tax->get_rates( $_product->get_tax_class() );
-
- $item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
-
- /**
- * ADJUST TAX - Calculations when base tax is not equal to the item tax
- */
- if ( $item_tax_rates !== $base_tax_rates ) {
-
- // Work out a new base price without the shop's base tax
- $line_tax = array_sum( $this->tax->calc_tax( $line_price, $base_tax_rates, true ) );
-
- // Now we have a new item price (excluding TAX)
- $line_subtotal = $this->tax->round( $line_price - $line_tax );
-
- // Now add taxes for the users location
- $line_subtotal_tax = array_sum( $this->tax->calc_tax( $line_subtotal, $item_tax_rates, false ) );
- $line_subtotal_tax = $this->round_at_subtotal ? $line_subtotal_tax : $this->tax->round( $line_subtotal_tax );
-
- // Adjusted price (this is the price including the new tax rate)
- $adjusted_price = ( $line_subtotal + $line_subtotal_tax ) / $values['quantity'];
-
- // Apply discounts
- $discounted_price = $this->get_discounted_price( $values, $adjusted_price, true );
- $discounted_taxes = $this->tax->calc_tax( $discounted_price * $values['quantity'], $item_tax_rates, true );
- $discounted_tax_amount = array_sum( $discounted_taxes ); // Sum taxes
-
- /**
- * Regular tax calculation (customer inside base and the tax class is unmodified
- */
- } else {
-
- // Calc tax normally
- $line_subtotal_tax = array_sum( $this->tax->calc_tax( $line_price, $item_tax_rates, true ) );
- $line_subtotal_tax = $this->round_at_subtotal ? $line_subtotal_tax : $this->tax->round( $line_subtotal_tax );
-
- // Subtotal
- $line_subtotal = $line_price - $line_subtotal_tax;
-
- // Calc prices and tax (discounted)
- $discounted_price = $this->get_discounted_price( $values, $base_price, true );
- $discounted_taxes = $this->tax->calc_tax( $discounted_price * $values['quantity'], $item_tax_rates, true );
- $discounted_tax_amount = array_sum( $discounted_taxes ); // Sum taxes
- }
-
- // Tax rows - merge the totals we just got
- foreach ( array_keys( $this->taxes + $discounted_taxes ) as $key ) {
- $this->taxes[ $key ] = ( isset( $discounted_taxes[ $key ] ) ? $discounted_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
- }
- }
-
- // Line prices
- $line_tax = $this->round_at_subtotal ? $discounted_tax_amount : $this->tax->round( $discounted_tax_amount );
- $line_total = $this->tax->round( ( $discounted_price * $values['quantity'] ) - $line_tax );
-
- // Add any product discounts (after tax)
- $this->apply_product_discounts_after_tax( $values, $line_total + $discounted_tax_amount );
-
- // Cart contents total is based on discounted prices and is used for the final total calculation
- $this->cart_contents_total = $this->cart_contents_total + $line_total;
-
- // Store costs + taxes for lines
- $this->cart_contents[ $cart_item_key ]['line_total'] = $line_total;
- $this->cart_contents[ $cart_item_key ]['line_tax'] = $line_tax;
- $this->cart_contents[ $cart_item_key ]['line_subtotal'] = $line_subtotal;
- $this->cart_contents[ $cart_item_key ]['line_subtotal_tax'] = $line_subtotal_tax;
+ // Base tax for line before discount - we will store this in the order data
+ $taxes = $this->tax->calc_tax( $line_price, $item_tax_rates );
+ $line_subtotal_tax = array_sum( $taxes );
+ $line_subtotal = $line_price;
}
- } else {
+ // Add to main subtotal
+ $this->subtotal += $line_subtotal + $line_subtotal_tax;
+ $this->subtotal_ex_tax += $line_subtotal;
+ }
- foreach ( $this->get_cart() as $cart_item_key => $values ) {
+ /**
+ * Calculate totals for items
+ */
+ foreach ( $this->get_cart() as $cart_item_key => $values ) {
+
+ $_product = $values['data'];
+
+ // Prices
+ $base_price = $_product->get_price();
+ $line_price = $_product->get_price() * $values['quantity'];
+
+ /**
+ * No tax to calculate
+ */
+ if ( ! $_product->is_taxable() ) {
+
+ // Discounted Price (price with any pre-tax discounts applied)
+ $discounted_price = $this->get_discounted_price( $values, $base_price, true );
+ $discounted_tax_amount = 0;
+ $tax_amount = 0;
+ $line_subtotal_tax = 0;
+ $line_subtotal = $line_price;
+ $line_tax = 0;
+ $line_total = $this->tax->round( $discounted_price * $values['quantity'] );
+
+ /**
+ * Prices include tax
+ */
+ } elseif ( $this->prices_include_tax ) {
+
+ $base_tax_rates = $shop_tax_rates[ $_product->tax_class ];
+ $item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
/**
- * Prices exclude tax
- *
- * This calculation is simpler - work with the base, untaxed price.
+ * ADJUST TAX - Calculations when base tax is not equal to the item tax
*/
- $_product = $values['data'];
+ if ( $item_tax_rates !== $base_tax_rates ) {
- // Prices
- $base_price = $_product->get_price();
- $line_price = $_product->get_price() * $values['quantity'];
+ // Work out a new base price without the shop's base tax
+ $taxes = $this->tax->calc_tax( $line_price, $base_tax_rates, true, true );
+
+ // Now we have a new item price (excluding TAX)
+ $line_subtotal = $line_price - array_sum( $taxes );
+
+ // Now add modifed taxes
+ $taxes = $this->tax->calc_tax( $line_subtotal, $item_tax_rates );
+ $line_subtotal_tax = array_sum( $taxes );
+
+ // Adjusted price (this is the price including the new tax rate)
+ $adjusted_price = ( $line_subtotal + $line_subtotal_tax ) / $values['quantity'];
+
+ // Apply discounts
+ $discounted_price = $this->get_discounted_price( $values, $adjusted_price, true );
+ $discounted_taxes = $this->tax->calc_tax( $discounted_price * $values['quantity'], $item_tax_rates, true );
+ $line_tax = array_sum( $discounted_taxes );
+ $line_total = ( $discounted_price * $values['quantity'] ) - $line_tax;
- // Discounted Price (base price with any pre-tax discounts applied
- $discounted_price = $this->get_discounted_price( $values, $base_price, true );
-
- // Taxes
- if ( ! $_product->is_taxable() ) {
- $discounted_tax_amount = 0;
- $line_subtotal_tax = 0;
+ /**
+ * Regular tax calculation (customer inside base and the tax class is unmodified
+ */
} else {
- // Get item tax rates
- if ( empty( $tax_rates[ $_product->get_tax_class() ] ) )
- $tax_rates[ $_product->get_tax_class() ] = $this->tax->get_rates( $_product->get_tax_class() );
+ // Work out a new base price without the shop's base tax
+ $taxes = $this->tax->calc_tax( $line_price, $item_tax_rates, true );
+
+ // Now we have a new item price (excluding TAX)
+ $line_subtotal = $line_price - array_sum( $taxes );
+ $line_subtotal_tax = array_sum( $taxes );
- $item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
-
- // Base tax for line before discount - we will store this in the order data
- $line_subtotal_tax = array_sum( $this->tax->calc_tax( $line_price, $item_tax_rates, false ) );
-
- // Now calc product rates
- $discounted_taxes = $this->tax->calc_tax( $discounted_price * $values['quantity'], $item_tax_rates, false );
- $discounted_tax_amount = array_sum( $discounted_taxes );
-
- // Tax rows - merge the totals we just got
- foreach ( array_keys( $this->taxes + $discounted_taxes ) as $key ) {
- $this->taxes[ $key ] = ( isset( $discounted_taxes[ $key ] ) ? $discounted_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
- }
+ // Calc prices and tax (discounted)
+ $discounted_price = $this->get_discounted_price( $values, $base_price, true );
+ $discounted_taxes = $this->tax->calc_tax( $discounted_price * $values['quantity'], $item_tax_rates, true );
+ $line_tax = array_sum( $discounted_taxes );
+ $line_total = ( $discounted_price * $values['quantity'] ) - $line_tax;
}
- // Line prices
- $line_tax = $discounted_tax_amount;
- $line_subtotal = $line_price;
- $line_total = $discounted_price * $values['quantity'];
+ // Tax rows - merge the totals we just got
+ foreach ( array_keys( $this->taxes + $discounted_taxes ) as $key ) {
+ $this->taxes[ $key ] = ( isset( $discounted_taxes[ $key ] ) ? $discounted_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
+ }
- // Add any product discounts (after tax)
- $this->apply_product_discounts_after_tax( $values, $line_total + $line_tax );
+ /**
+ * Prices exclude tax
+ */
+ } else {
+
+ $item_tax_rates = $tax_rates[ $_product->get_tax_class() ];
+
+ // Work out a new base price without the shop's base tax
+ $taxes = $this->tax->calc_tax( $line_price, $item_tax_rates );
+
+ // Now we have a new item price (excluding TAX)
+ $line_subtotal = $line_price - array_sum( $taxes );
+ $line_subtotal_tax = array_sum( $taxes );
+
+ // Now calc product rates
+ $discounted_price = $this->get_discounted_price( $values, $base_price, true );
+ $discounted_taxes = $this->tax->calc_tax( $discounted_price * $values['quantity'], $item_tax_rates );
+ $discounted_tax_amount = array_sum( $discounted_taxes );
+ $line_tax = $discounted_tax_amount;
+ $line_total = ( $discounted_price * $values['quantity'] ) - $line_tax;
- // Cart contents total is based on discounted prices and is used for the final total calculation
- $this->cart_contents_total = $this->cart_contents_total + $line_total;
-
- // Store costs + taxes for lines
- $this->cart_contents[ $cart_item_key ]['line_total'] = $line_total;
- $this->cart_contents[ $cart_item_key ]['line_tax'] = $line_tax;
- $this->cart_contents[ $cart_item_key ]['line_subtotal'] = $line_subtotal;
- $this->cart_contents[ $cart_item_key ]['line_subtotal_tax'] = $line_subtotal_tax;
+ // Tax rows - merge the totals we just got
+ foreach ( array_keys( $this->taxes + $discounted_taxes ) as $key ) {
+ $this->taxes[ $key ] = ( isset( $discounted_taxes[ $key ] ) ? $discounted_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
+ }
}
+
+ // Add any product discounts (after tax)
+ $this->apply_product_discounts_after_tax( $values, $line_total + $line_tax );
+
+ // Cart contents total is based on discounted prices and is used for the final total calculation
+ $this->cart_contents_total += $line_total;
+
+ // Store costs + taxes for lines
+ $this->cart_contents[ $cart_item_key ]['line_total'] = $line_total;
+ $this->cart_contents[ $cart_item_key ]['line_tax'] = $line_tax;
+ $this->cart_contents[ $cart_item_key ]['line_subtotal'] = $line_subtotal;
+ $this->cart_contents[ $cart_item_key ]['line_subtotal_tax'] = $line_subtotal_tax;
}
// Only calculate the grand total + shipping if on the cart/checkout
@@ -1232,19 +1184,14 @@ class WC_Cart {
// Trigger the fees API where developers can add fees to the cart
$this->calculate_fees();
- // Total up/round taxes
+ // Total up/round taxes and shipping taxes
if ( $this->round_at_subtotal ) {
$this->tax_total = $this->tax->get_tax_total( $this->taxes );
- $this->taxes = array_map( array( $this->tax, 'round' ), $this->taxes );
- } else {
- $this->tax_total = array_sum( $this->taxes );
- }
-
- // Total up/round taxes for shipping
- if ( $this->round_at_subtotal ) {
$this->shipping_tax_total = $this->tax->get_tax_total( $this->shipping_taxes );
+ $this->taxes = array_map( array( $this->tax, 'round' ), $this->taxes );
$this->shipping_taxes = array_map( array( $this->tax, 'round' ), $this->shipping_taxes );
} else {
+ $this->tax_total = array_sum( $this->taxes );
$this->shipping_tax_total = array_sum( $this->shipping_taxes );
}
@@ -1870,13 +1817,11 @@ class WC_Cart {
// Get tax rates
$tax_rates = $this->tax->get_rates( $fee->tax_class );
$fee_taxes = $this->tax->calc_tax( $fee->amount, $tax_rates, false );
-
- // Store
- $fee->tax = array_sum( $fee_taxes );
+ $fee->tax = $fee_taxes['total_tax'];
// Tax rows - merge the totals we just got
- foreach ( array_keys( $this->taxes + $fee_taxes ) as $key ) {
- $this->taxes[ $key ] = ( isset( $fee_taxes[ $key ] ) ? $fee_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
+ foreach ( array_keys( $this->taxes + $fee_taxes['taxes'] ) as $key ) {
+ $this->taxes[ $key ] = ( isset( $fee_taxes['taxes'][ $key ] ) ? $fee_taxes['taxes'][ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
}
}
}
@@ -1952,7 +1897,7 @@ class WC_Cart {
// cart + shipping + non-compound taxes (after discount)
if ( $compound ) {
- $cart_subtotal = woocommerce_price( $this->cart_contents_total + $this->shipping_total + $this->get_taxes_total( false ) );
+ $cart_subtotal = woocommerce_price( $this->cart_contents_total + $this->shipping_total + $this->get_taxes_total( false, false ) );
// Otherwise we show cart items totals only (before discount)
} else {
@@ -2057,10 +2002,11 @@ class WC_Cart {
/**
* Get tax row amounts with or without compound taxes includes.
- *
+ * @param boolean $compound True if getting compound taxes
+ * @param boolean $display True if getting total to display
* @return float price
*/
- public function get_taxes_total( $compound = true ) {
+ public function get_taxes_total( $compound = true, $display = true ) {
$total = 0;
foreach ( $this->taxes as $key => $tax ) {
if ( ! $compound && $this->tax->is_compound( $key ) ) continue;
@@ -2070,7 +2016,10 @@ class WC_Cart {
if ( ! $compound && $this->tax->is_compound( $key ) ) continue;
$total += $tax;
}
- return $total;
+ if ( $display )
+ return woocommerce_round_tax_total( $total );
+ else
+ return $total;
}
/**
diff --git a/includes/class-wc-checkout.php b/includes/class-wc-checkout.php
index ac5e5b74a16..278c6f380d4 100644
--- a/includes/class-wc-checkout.php
+++ b/includes/class-wc-checkout.php
@@ -80,8 +80,6 @@ class WC_Checkout {
* @return void
*/
public function __construct () {
- global $woocommerce;
-
add_action( 'woocommerce_checkout_billing', array( $this,'checkout_form_billing' ) );
add_action( 'woocommerce_checkout_shipping', array( $this,'checkout_form_shipping' ) );
@@ -90,8 +88,8 @@ class WC_Checkout {
$this->must_create_account = $this->enable_guest_checkout || is_user_logged_in() ? false : true;
// Define all Checkout fields
- $this->checkout_fields['billing'] = $woocommerce->countries->get_address_fields( $this->get_value('billing_country'), 'billing_' );
- $this->checkout_fields['shipping'] = $woocommerce->countries->get_address_fields( $this->get_value('shipping_country'), 'shipping_' );
+ $this->checkout_fields['billing'] = WC()->countries->get_address_fields( $this->get_value('billing_country'), 'billing_' );
+ $this->checkout_fields['shipping'] = WC()->countries->get_address_fields( $this->get_value('shipping_country'), 'shipping_' );
if ( get_option( 'woocommerce_registration_generate_username' ) == 'no' ) {
$this->checkout_fields['account']['account_username'] = array(
@@ -164,7 +162,7 @@ class WC_Checkout {
* @return int
*/
public function create_order() {
- global $woocommerce, $wpdb;
+ global $wpdb;
// Give plugins the opportunity to create an order themselves
$order_id = apply_filters( 'woocommerce_create_order', null, $this );
@@ -186,9 +184,9 @@ class WC_Checkout {
// Insert or update the post data
$create_new_order = true;
- if ( $woocommerce->session->order_awaiting_payment > 0 ) {
+ if ( WC()->session->order_awaiting_payment > 0 ) {
- $order_id = absint( $woocommerce->session->order_awaiting_payment );
+ $order_id = absint( WC()->session->order_awaiting_payment );
/* Check order is unpaid by getting its status */
$terms = wp_get_object_terms( $order_id, 'shop_order_status', array( 'fields' => 'slugs' ) );
@@ -230,7 +228,7 @@ class WC_Checkout {
update_user_meta( $this->customer_id, $key, $this->posted[ $key ] );
}
- if ( $this->checkout_fields['shipping'] && $woocommerce->cart->needs_shipping() ) {
+ if ( $this->checkout_fields['shipping'] && WC()->cart->needs_shipping() ) {
foreach ( $this->checkout_fields['shipping'] as $key => $field ) {
$postvalue = false;
@@ -255,7 +253,7 @@ class WC_Checkout {
do_action( 'woocommerce_checkout_update_user_meta', $this->customer_id, $this->posted );
// Store the line items to the new/resumed order
- foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
+ foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
@@ -271,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'], 4 ) );
- woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'], 4 ) );
- woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $values['line_tax'], 4 ) );
- woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $values['line_subtotal_tax'], 4 ) );
+ 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 ) );
// Store variation data in meta so admin can view it
if ( $values['variation'] && is_array( $values['variation'] ) )
@@ -291,7 +289,7 @@ class WC_Checkout {
}
// Store fees
- foreach ( $woocommerce->cart->get_fees() as $fee ) {
+ foreach ( WC()->cart->get_fees() as $fee ) {
$item_id = woocommerce_add_order_item( $order_id, array(
'order_item_name' => $fee->name,
'order_item_type' => 'fee'
@@ -302,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 ) );
- woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $fee->tax ) );
+ 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 ) );
}
// Store shipping for all packages
@@ -321,31 +319,31 @@ 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 ) );
+ woocommerce_add_order_item_meta( $item_id, 'cost', woocommerce_format_decimal( $method->cost, false ) );
}
}
}
// Store tax rows
- foreach ( array_keys( $woocommerce->cart->taxes + $woocommerce->cart->shipping_taxes ) as $key ) {
+ foreach ( array_keys( WC()->cart->taxes + WC()->cart->shipping_taxes ) as $key ) {
$item_id = woocommerce_add_order_item( $order_id, array(
- 'order_item_name' => $woocommerce->cart->tax->get_rate_code( $key ),
+ 'order_item_name' => WC()->cart->tax->get_rate_code( $key ),
'order_item_type' => 'tax'
) );
// Add line item meta
if ( $item_id ) {
woocommerce_add_order_item_meta( $item_id, 'rate_id', $key );
- woocommerce_add_order_item_meta( $item_id, 'label', $woocommerce->cart->tax->get_rate_label( $key ) );
- woocommerce_add_order_item_meta( $item_id, 'compound', absint( $woocommerce->cart->tax->is_compound( $key ) ? 1 : 0 ) );
- woocommerce_add_order_item_meta( $item_id, 'tax_amount', woocommerce_format_decimal( isset( $woocommerce->cart->taxes[ $key ] ) ? $woocommerce->cart->taxes[ $key ] : 0 ), false );
- woocommerce_add_order_item_meta( $item_id, 'shipping_tax_amount', woocommerce_format_decimal( isset( $woocommerce->cart->shipping_taxes[ $key ] ) ? $woocommerce->cart->shipping_taxes[ $key ] : 0 ), false );
+ 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 ) );
}
}
// Store coupons
- if ( $applied_coupons = $woocommerce->cart->get_coupons() ) {
+ if ( $applied_coupons = WC()->cart->get_coupons() ) {
foreach ( $applied_coupons as $code => $coupon ) {
$item_id = woocommerce_add_order_item( $order_id, array(
@@ -355,7 +353,7 @@ class WC_Checkout {
// Add line item meta
if ( $item_id ) {
- woocommerce_add_order_item_meta( $item_id, 'discount_amount', isset( $woocommerce->cart->coupon_discount_amounts[ $code ] ) ? $woocommerce->cart->coupon_discount_amounts[ $code ] : 0 );
+ woocommerce_add_order_item_meta( $item_id, 'discount_amount', isset( WC()->cart->coupon_discount_amounts[ $code ] ) ? WC()->cart->coupon_discount_amounts[ $code ] : 0 );
}
}
}
@@ -364,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( $woocommerce->cart->shipping_total ) );
- update_post_meta( $order_id, '_order_discount', woocommerce_format_decimal( $woocommerce->cart->get_order_discount_total() ) );
- update_post_meta( $order_id, '_cart_discount', woocommerce_format_decimal( $woocommerce->cart->get_cart_discount_total() ) );
- update_post_meta( $order_id, '_order_tax', woocommerce_format_decimal( $woocommerce->cart->tax_total, false ) );
- update_post_meta( $order_id, '_order_shipping_tax', woocommerce_format_decimal( $woocommerce->cart->shipping_tax_total, false ) );
- update_post_meta( $order_id, '_order_total', woocommerce_format_decimal( $woocommerce->cart->total ) );
+ 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_key', apply_filters('woocommerce_generate_order_key', uniqid('order_') ) );
update_post_meta( $order_id, '_customer_user', absint( $this->customer_id ) );
@@ -394,7 +392,7 @@ class WC_Checkout {
* @return void
*/
public function process_checkout() {
- global $wpdb, $woocommerce, $current_user;
+ global $wpdb, $current_user;
wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-process_checkout' );
@@ -406,7 +404,7 @@ class WC_Checkout {
do_action( 'woocommerce_before_checkout_process' );
- if ( sizeof( $woocommerce->cart->get_cart() ) == 0 )
+ if ( sizeof( WC()->cart->get_cart() ) == 0 )
wc_add_error( sprintf( __( 'Sorry, your session has expired. Return to homepage →', 'woocommerce' ), home_url() ) );
do_action( 'woocommerce_checkout_process' );
@@ -425,7 +423,7 @@ class WC_Checkout {
}
// Ship to billing only option
- if ( $woocommerce->cart->ship_to_billing_address_only() )
+ if ( WC()->cart->ship_to_billing_address_only() )
$this->posted['ship_to_different_address'] = false;
// Update customer shipping and payment method to posted method
@@ -445,7 +443,7 @@ class WC_Checkout {
foreach ( $this->checkout_fields as $fieldset_key => $fieldset ) {
// Skip shipping if not needed
- if ( $fieldset_key == 'shipping' && ( $this->posted['ship_to_different_address'] == false || ! $woocommerce->cart->needs_shipping() ) ) {
+ if ( $fieldset_key == 'shipping' && ( $this->posted['ship_to_different_address'] == false || ! WC()->cart->needs_shipping() ) ) {
$skipped_shipping = true;
continue;
}
@@ -513,7 +511,7 @@ class WC_Checkout {
break;
case 'state' :
// Get valid states
- $valid_states = $woocommerce->countries->get_states( $_POST[ $fieldset_key . '_country' ] );
+ $valid_states = WC()->countries->get_states( $_POST[ $fieldset_key . '_country' ] );
if ( $valid_states )
$valid_state_values = array_flip( array_map( 'strtolower', $valid_states ) );
@@ -535,46 +533,46 @@ class WC_Checkout {
// Update customer location to posted location so we can correctly check available shipping methods
if ( isset( $this->posted['billing_country'] ) )
- $woocommerce->customer->set_country( $this->posted['billing_country'] );
+ WC()->customer->set_country( $this->posted['billing_country'] );
if ( isset( $this->posted['billing_state'] ) )
- $woocommerce->customer->set_state( $this->posted['billing_state'] );
+ WC()->customer->set_state( $this->posted['billing_state'] );
if ( isset( $this->posted['billing_postcode'] ) )
- $woocommerce->customer->set_postcode( $this->posted['billing_postcode'] );
+ WC()->customer->set_postcode( $this->posted['billing_postcode'] );
// Shipping Information
if ( ! $skipped_shipping ) {
// Update customer location to posted location so we can correctly check available shipping methods
if ( isset( $this->posted['shipping_country'] ) )
- $woocommerce->customer->set_shipping_country( $this->posted['shipping_country'] );
+ WC()->customer->set_shipping_country( $this->posted['shipping_country'] );
if ( isset( $this->posted['shipping_state'] ) )
- $woocommerce->customer->set_shipping_state( $this->posted['shipping_state'] );
+ WC()->customer->set_shipping_state( $this->posted['shipping_state'] );
if ( isset( $this->posted['shipping_postcode'] ) )
- $woocommerce->customer->set_shipping_postcode( $this->posted['shipping_postcode'] );
+ WC()->customer->set_shipping_postcode( $this->posted['shipping_postcode'] );
} else {
// Update customer location to posted location so we can correctly check available shipping methods
if ( isset( $this->posted['billing_country'] ) )
- $woocommerce->customer->set_shipping_country( $this->posted['billing_country'] );
+ WC()->customer->set_shipping_country( $this->posted['billing_country'] );
if ( isset( $this->posted['billing_state'] ) )
- $woocommerce->customer->set_shipping_state( $this->posted['billing_state'] );
+ WC()->customer->set_shipping_state( $this->posted['billing_state'] );
if ( isset( $this->posted['billing_postcode'] ) )
- $woocommerce->customer->set_shipping_postcode( $this->posted['billing_postcode'] );
+ WC()->customer->set_shipping_postcode( $this->posted['billing_postcode'] );
}
// Update cart totals now we have customer address
- $woocommerce->cart->calculate_totals();
+ WC()->cart->calculate_totals();
// Terms
if ( ! isset( $_POST['woocommerce_checkout_update_totals'] ) && empty( $this->posted['terms'] ) && woocommerce_get_page_id( 'terms' ) > 0 )
wc_add_error( __( 'You must accept our Terms & Conditions.', 'woocommerce' ) );
- if ( $woocommerce->cart->needs_shipping() ) {
+ if ( WC()->cart->needs_shipping() ) {
- if ( ! in_array( $woocommerce->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) )
- wc_add_error( sprintf( __( 'Unfortunately we do not ship to %s. Please enter an alternative shipping address.', 'woocommerce' ), $woocommerce->countries->shipping_to_prefix() . ' ' . $woocommerce->customer->get_shipping_country() ) );
+ if ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) )
+ wc_add_error( sprintf( __( 'Unfortunately we do not ship to %s. Please enter an alternative shipping address.', 'woocommerce' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
// Validate Shipping Methods
$packages = WC()->shipping->get_packages();
@@ -588,10 +586,10 @@ class WC_Checkout {
}
}
- if ( $woocommerce->cart->needs_payment() ) {
+ if ( WC()->cart->needs_payment() ) {
// Payment Method
- $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways();
+ $available_gateways = WC()->payment_gateways->get_available_payment_gateways();
if ( ! isset( $available_gateways[ $this->posted['payment_method'] ] ) ) {
$this->payment_method = '';
@@ -648,10 +646,10 @@ class WC_Checkout {
do_action( 'woocommerce_checkout_order_processed', $order_id, $this->posted );
// Process payment
- if ( $woocommerce->cart->needs_payment() ) {
+ if ( WC()->cart->needs_payment() ) {
// Store Order ID in session so it can be re-used after payment failure
- $woocommerce->session->order_awaiting_payment = $order_id;
+ WC()->session->order_awaiting_payment = $order_id;
// Process Payment
$result = $available_gateways[ $this->posted['payment_method'] ]->process_payment( $order_id );
@@ -680,7 +678,7 @@ class WC_Checkout {
$order->payment_complete();
// Empty the Cart
- $woocommerce->cart->empty_cart();
+ WC()->cart->empty_cart();
// Get redirect
$return_url = $order->get_checkout_order_received_url();
@@ -723,12 +721,12 @@ class WC_Checkout {
array(
'result' => 'failure',
'messages' => $messages,
- 'refresh' => isset( $woocommerce->session->refresh_totals ) ? 'true' : 'false',
- 'reload' => isset( $woocommerce->session->reload_checkout ) ? 'true' : 'false'
+ 'refresh' => isset( WC()->session->refresh_totals ) ? 'true' : 'false',
+ 'reload' => isset( WC()->session->reload_checkout ) ? 'true' : 'false'
)
) . '';
- unset( $woocommerce->session->refresh_totals, $woocommerce->session->reload_checkout );
+ unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
exit;
}
}
@@ -742,8 +740,6 @@ class WC_Checkout {
* @return string
*/
public function get_value( $input ) {
- global $woocommerce;
-
if ( ! empty( $_POST[ $input ] ) ) {
return woocommerce_clean( $_POST[ $input ] );
@@ -768,17 +764,17 @@ class WC_Checkout {
switch ( $input ) {
case "billing_country" :
- return apply_filters( 'default_checkout_country', $woocommerce->customer->get_country() ? $woocommerce->customer->get_country() : $woocommerce->countries->get_base_country(), 'billing' );
+ return apply_filters( 'default_checkout_country', WC()->customer->get_country() ? WC()->customer->get_country() : WC()->countries->get_base_country(), 'billing' );
case "billing_state" :
- return apply_filters( 'default_checkout_state', $woocommerce->customer->has_calculated_shipping() ? $woocommerce->customer->get_state() : '', 'billing' );
+ return apply_filters( 'default_checkout_state', WC()->customer->has_calculated_shipping() ? WC()->customer->get_state() : '', 'billing' );
case "billing_postcode" :
- return apply_filters( 'default_checkout_postcode', $woocommerce->customer->get_postcode() ? $woocommerce->customer->get_postcode() : '', 'billing' );
+ return apply_filters( 'default_checkout_postcode', WC()->customer->get_postcode() ? WC()->customer->get_postcode() : '', 'billing' );
case "shipping_country" :
- return apply_filters( 'default_checkout_country', $woocommerce->customer->get_shipping_country() ? $woocommerce->customer->get_shipping_country() : $woocommerce->countries->get_base_country(), 'shipping' );
+ return apply_filters( 'default_checkout_country', WC()->customer->get_shipping_country() ? WC()->customer->get_shipping_country() : WC()->countries->get_base_country(), 'shipping' );
case "shipping_state" :
- return apply_filters( 'default_checkout_state', $woocommerce->customer->has_calculated_shipping() ? $woocommerce->customer->get_shipping_state() : '', 'shipping' );
+ return apply_filters( 'default_checkout_state', WC()->customer->has_calculated_shipping() ? WC()->customer->get_shipping_state() : '', 'shipping' );
case "shipping_postcode" :
- return apply_filters( 'default_checkout_postcode', $woocommerce->customer->get_shipping_postcode() ? $woocommerce->customer->get_shipping_postcode() : '', 'shipping' );
+ return apply_filters( 'default_checkout_postcode', WC()->customer->get_shipping_postcode() ? WC()->customer->get_shipping_postcode() : '', 'shipping' );
default :
return apply_filters( 'default_checkout_' . $input, '', $input );
}
diff --git a/includes/class-wc-form-handler.php b/includes/class-wc-form-handler.php
index c35a8eb37ea..6d8d9b7d1e6 100644
--- a/includes/class-wc-form-handler.php
+++ b/includes/class-wc-form-handler.php
@@ -506,7 +506,7 @@ class WC_Form_Handler {
$variations[ $taxonomy ] = $value;
else {
// For custom attributes, get the name from the slug
- $options = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
+ $options = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
foreach ( $options as $option ) {
if ( sanitize_title( $option ) == $value ) {
$value = $option;
diff --git a/includes/class-wc-frontend-scripts.php b/includes/class-wc-frontend-scripts.php
index e2696bcb502..e69b5d5c32a 100644
--- a/includes/class-wc-frontend-scripts.php
+++ b/includes/class-wc-frontend-scripts.php
@@ -22,19 +22,19 @@ class WC_Frontend_Scripts {
'woocommerce-layout' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-layout.css',
'deps' => '',
- 'version' => WOOCOMMERCE_VERSION,
+ 'version' => WC_VERSION,
'media' => ''
),
'woocommerce-smallscreen' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-smallscreen.css',
'deps' => 'woocommerce-layout',
- 'version' => WOOCOMMERCE_VERSION,
+ 'version' => WC_VERSION,
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
),
'woocommerce-general' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce.css',
'deps' => '',
- 'version' => WOOCOMMERCE_VERSION,
+ 'version' => WC_VERSION,
'media' => ''
),
) );
@@ -58,35 +58,35 @@ class WC_Frontend_Scripts {
// Register any scripts for later use, or used as dependencies
wp_register_script( 'chosen', $assets_path . 'js/chosen/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '0.9.14', true );
wp_register_script( 'jquery-blockui', $assets_path . 'js/jquery-blockui/jquery.blockUI' . $suffix . '.js', array( 'jquery' ), '2.60', true );
- wp_register_script( 'jquery-placeholder', $assets_path . 'js/jquery-placeholder/jquery.placeholder' . $suffix . '.js', array( 'jquery' ), WOOCOMMERCE_VERSION, true );
+ wp_register_script( 'jquery-placeholder', $assets_path . 'js/jquery-placeholder/jquery.placeholder' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'jquery-payment', $assets_path . 'js/jquery-payment/jquery.payment' . $suffix . '.js', array( 'jquery' ), '1.0.2', true );
- wp_register_script( 'wc-credit-card-form', $assets_path . 'js/frontend/credit-card-form' . $suffix . '.js', array( 'jquery', 'jquery-payment' ), WOOCOMMERCE_VERSION, true );
+ wp_register_script( 'wc-credit-card-form', $assets_path . 'js/frontend/credit-card-form' . $suffix . '.js', array( 'jquery', 'jquery-payment' ), WC_VERSION, true );
- wp_register_script( 'wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array( 'jquery' ), WOOCOMMERCE_VERSION, true );
- wp_register_script( 'wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array( 'jquery' ), WOOCOMMERCE_VERSION, true );
- wp_register_script( 'wc-country-select', $frontend_script_path . 'country-select' . $suffix . '.js', array( 'jquery' ), WOOCOMMERCE_VERSION, true );
+ wp_register_script( 'wc-add-to-cart-variation', $frontend_script_path . 'add-to-cart-variation' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
+ wp_register_script( 'wc-single-product', $frontend_script_path . 'single-product' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
+ wp_register_script( 'wc-country-select', $frontend_script_path . 'country-select' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_register_script( 'jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie' . $suffix . '.js', array( 'jquery' ), '1.3.1', true );
// Queue frontend scripts conditionally
if ( $ajax_cart_en )
- wp_enqueue_script( 'wc-add-to-cart', $frontend_script_path . 'add-to-cart' . $suffix . '.js', array( 'jquery' ), WOOCOMMERCE_VERSION, true );
+ wp_enqueue_script( 'wc-add-to-cart', $frontend_script_path . 'add-to-cart' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
if ( is_cart() )
- wp_enqueue_script( 'wc-cart', $frontend_script_path . 'cart' . $suffix . '.js', array( 'jquery', 'wc-country-select' ), WOOCOMMERCE_VERSION, true );
+ wp_enqueue_script( 'wc-cart', $frontend_script_path . 'cart' . $suffix . '.js', array( 'jquery', 'wc-country-select' ), WC_VERSION, true );
if ( is_checkout() ) {
if ( get_option( 'woocommerce_enable_chosen' ) == 'yes' ) {
- wp_enqueue_script( 'wc-chosen', $frontend_script_path . 'chosen-frontend' . $suffix . '.js', array( 'chosen' ), WOOCOMMERCE_VERSION, true );
+ wp_enqueue_script( 'wc-chosen', $frontend_script_path . 'chosen-frontend' . $suffix . '.js', array( 'chosen' ), WC_VERSION, true );
wp_enqueue_style( 'woocommerce_chosen_styles', $assets_path . 'css/chosen.css' );
}
- wp_enqueue_script( 'wc-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array( 'jquery', 'woocommerce', 'wc-country-select' ), WOOCOMMERCE_VERSION, true );
+ wp_enqueue_script( 'wc-checkout', $frontend_script_path . 'checkout' . $suffix . '.js', array( 'jquery', 'woocommerce', 'wc-country-select' ), WC_VERSION, true );
}
if ( $lightbox_en && ( is_product() || ( ! empty( $post->post_content ) && strstr( $post->post_content, '[product_page' ) ) ) ) {
wp_enqueue_script( 'prettyPhoto', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto' . $suffix . '.js', array( 'jquery' ), '3.1.5', true );
- wp_enqueue_script( 'prettyPhoto-init', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array( 'jquery' ), WOOCOMMERCE_VERSION, true );
+ wp_enqueue_script( 'prettyPhoto-init', $assets_path . 'js/prettyPhoto/jquery.prettyPhoto.init' . $suffix . '.js', array( 'jquery' ), WC_VERSION, true );
wp_enqueue_style( 'woocommerce_prettyPhoto_css', $assets_path . 'css/prettyPhoto.css' );
}
@@ -94,8 +94,8 @@ class WC_Frontend_Scripts {
wp_enqueue_script( 'wc-single-product' );
// Global frontend scripts
- wp_enqueue_script( 'woocommerce', $frontend_script_path . 'woocommerce' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-placeholder' ), WOOCOMMERCE_VERSION, true );
- wp_enqueue_script( 'wc-cart-fragments', $frontend_script_path . 'cart-fragments' . $suffix . '.js', array( 'jquery', 'jquery-cookie' ), WOOCOMMERCE_VERSION, true );
+ wp_enqueue_script( 'woocommerce', $frontend_script_path . 'woocommerce' . $suffix . '.js', array( 'jquery', 'jquery-blockui', 'jquery-placeholder' ), WC_VERSION, true );
+ wp_enqueue_script( 'wc-cart-fragments', $frontend_script_path . 'cart-fragments' . $suffix . '.js', array( 'jquery', 'jquery-cookie' ), WC_VERSION, true );
// Variables for JS scripts
wp_localize_script( 'woocommerce', 'woocommerce_params', apply_filters( 'woocommerce_params', array(
diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php
index 3ff4c222c16..d1646eb808b 100644
--- a/includes/class-wc-install.php
+++ b/includes/class-wc-install.php
@@ -21,7 +21,7 @@ class WC_Install {
* Hook in tabs.
*/
public function __construct() {
- register_activation_hook( WOOCOMMERCE_PLUGIN_FILE, array( $this, 'install' ) );
+ register_activation_hook( WC_PLUGIN_FILE, array( $this, 'install' ) );
add_action( 'admin_init', array( $this, 'install_actions' ) );
add_action( 'admin_init', array( $this, 'check_version' ), 5 );
@@ -165,7 +165,7 @@ class WC_Install {
update_option( 'woocommerce_db_version', '2.0.14' );
}
- if ( version_compare( $current_db_version, '2.1.0', '<' ) || WOOCOMMERCE_VERSION == '2.1-bleeding' ) {
+ if ( version_compare( $current_db_version, '2.1.0', '<' ) || WC_VERSION == '2.1-bleeding' ) {
include( 'updates/woocommerce-update-2.1.php' );
update_option( 'woocommerce_db_version', '2.1.0' );
}
@@ -639,7 +639,7 @@ class WC_Install {
// Output Upgrade Notice
$matches = null;
- $regexp = '~==\s*Upgrade Notice\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*' . preg_quote( WOOCOMMERCE_VERSION ) . '\s*=|$)~Uis';
+ $regexp = '~==\s*Upgrade Notice\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*' . preg_quote( WC_VERSION ) . '\s*=|$)~Uis';
if ( preg_match( $regexp, $response['body'], $matches ) ) {
$notices = (array) preg_split('~[\r\n]+~', trim( $matches[1] ) );
@@ -655,7 +655,7 @@ class WC_Install {
// Output Changelog
$matches = null;
- $regexp = '~==\s*Changelog\s*==\s*=\s*[0-9.]+\s*-(.*)=(.*)(=\s*' . preg_quote( WOOCOMMERCE_VERSION ) . '\s*-(.*)=|$)~Uis';
+ $regexp = '~==\s*Changelog\s*==\s*=\s*[0-9.]+\s*-(.*)=(.*)(=\s*' . preg_quote( WC_VERSION ) . '\s*-(.*)=|$)~Uis';
if ( preg_match( $regexp, $response['body'], $matches ) ) {
$changelog = (array) preg_split('~[\r\n]+~', trim( $matches[2] ) );
diff --git a/includes/class-wc-order.php b/includes/class-wc-order.php
index 75cc1d8d6e8..3d58eb5b59d 100644
--- a/includes/class-wc-order.php
+++ b/includes/class-wc-order.php
@@ -384,7 +384,7 @@ class WC_Order {
$tax_totals[ $code ]->is_compound = $tax[ 'compound' ];
$tax_totals[ $code ]->label = isset( $tax[ 'label' ] ) ? $tax[ 'label' ] : $tax[ 'name' ];
$tax_totals[ $code ]->amount += $tax[ 'tax_amount' ] + $tax[ 'shipping_tax_amount' ];
- $tax_totals[ $code ]->formatted_amount = woocommerce_price( $tax_totals[ $code ]->amount );
+ $tax_totals[ $code ]->formatted_amount = woocommerce_price( woocommerce_round_tax_total( $tax_totals[ $code ]->amount ) );
}
return apply_filters( 'woocommerce_order_tax_totals', $tax_totals, $this );
@@ -476,7 +476,7 @@ class WC_Order {
* @return float
*/
public function get_total_tax() {
- return apply_filters( 'woocommerce_order_amount_total_tax', $this->get_cart_tax() + $this->get_shipping_tax(), $this );
+ return apply_filters( 'woocommerce_order_amount_total_tax', woocommerce_round_tax_total( $this->get_cart_tax() + $this->get_shipping_tax() ), $this );
}
/**
@@ -582,8 +582,8 @@ class WC_Order {
*/
public function get_item_tax( $item, $round = true ) {
$price = $item['line_tax'] / $item['qty'];
- $price = $round ? number_format( $price, 2, '.', '' ) : $price;
- return apply_filters( 'woocommerce_order_amount_item_tax', $price, $this );
+ $price = $round ? woocommerce_round_tax_total( $price ) : $price;
+ return apply_filters( 'woocommerce_order_amount_item_tax', $price, $item, $round, $this );
}
/**
@@ -594,7 +594,7 @@ class WC_Order {
* @return float
*/
public function get_line_tax( $item ) {
- return apply_filters( 'woocommerce_order_amount_line_tax', number_format( $item['line_tax'], 2, '.', ''), $this );
+ return apply_filters( 'woocommerce_order_amount_line_tax', woocommerce_round_tax_total( $item['line_tax'] ), $item, $this );
}
/**
diff --git a/includes/class-wc-product-variable.php b/includes/class-wc-product-variable.php
index 96cfd94a7cb..e1379e9e583 100644
--- a/includes/class-wc-product-variable.php
+++ b/includes/class-wc-product-variable.php
@@ -312,7 +312,7 @@ class WC_Product_Variable extends WC_Product {
foreach ( $post_terms as $term )
$values[] = $term->slug;
} else {
- $values = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
+ $values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
}
$values = array_unique( $values );
@@ -320,7 +320,7 @@ class WC_Product_Variable extends WC_Product {
// Order custom attributes (non taxonomy) as defined
} elseif ( ! $attribute['is_taxonomy'] ) {
- $option_names = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
+ $option_names = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
$option_slugs = $values;
$values = array();
diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php
index fd114a853f0..95ff69731bc 100644
--- a/includes/class-wc-tax.php
+++ b/includes/class-wc-tax.php
@@ -13,6 +13,9 @@ class WC_Tax {
/** @var array */
public $matched_rates;
+
+ var $log = array();
+
/**
* __construct function.
*
@@ -20,10 +23,182 @@ class WC_Tax {
* @return void
*/
public function __construct() {
+ $this->precision = WC_ROUNDING_PRECISION;
$this->dp = (int) get_option( 'woocommerce_price_num_decimals' );
$this->round_at_subtotal = get_option('woocommerce_tax_round_at_subtotal') == 'yes';
}
+ /**
+ * Calculate tax for a line
+ * @param float $price Price to calc tax on
+ * @param array $rates Rates to apply
+ * @param boolean $price_includes_tax Whether the passed price has taxes included
+ * @param boolean $suppress_rounding Whether to supress any rounding from taking place
+ * @return array Array of rates + prices after tax
+ */
+ public function calc_tax( $price, $rates, $price_includes_tax = false, $suppress_rounding = false ) {
+ // Work in pence to X precision
+ $price = $this->precision( $price );
+
+ if ( $price_includes_tax )
+ $taxes = $this->calc_inclusive_tax( $price, $rates );
+ else
+ $taxes = $this->calc_exclusive_tax( $price, $rates );
+
+ // Round to precision
+ if ( ! $this->round_at_subtotal && ! $suppress_rounding ) {
+ $taxes = array_map( 'round', $taxes ); // Round to precision
+ }
+
+ // Remove precision
+ $price = $this->remove_precision( $price );
+ $taxes = array_map( array( $this, 'remove_precision' ), $taxes );
+
+ return apply_filters( 'woocommerce_calc_tax', $taxes, $price, $rates, $price_includes_tax, $suppress_rounding );
+ }
+
+ /**
+ * Calculate the shipping tax using a passed array of rates.
+ *
+ * @param float Price
+ * @param array Taxation Rate
+ * @return array
+ */
+ public function calc_shipping_tax( $price, $rates ) {
+ return $this->calc_exclusive_tax( $price, $rates );
+ }
+
+ /**
+ * Multiply cost by pow precision
+ * @param float $price
+ * @return float
+ */
+ private function precision( $price ) {
+ return $price * ( pow( 10, $this->precision ) );
+ }
+
+ /**
+ * Divide cost by pow precision
+ * @param float $price
+ * @return float
+ */
+ private function remove_precision( $price ) {
+ return $price / ( pow( 10, $this->precision ) );
+ }
+
+ /**
+ * Round to precision.
+ *
+ * Filter example: to return rounding to .5 cents you'd use:
+ *
+ * public function euro_5cent_rounding( $in ) {
+ * return round( $in / 5, 2 ) * 5;
+ * }
+ * add_filter( 'woocommerce_tax_round', 'euro_5cent_rounding' );
+ */
+ public function round( $in ) {
+ return apply_filters( 'woocommerce_tax_round', round( $in, $this->precision ), $in );
+ }
+
+ /**
+ * Calc tax from inclusive price
+ *
+ * @param float $price
+ * @param array $rates
+ * @return array
+ */
+ private function calc_inclusive_tax( $price, $rates ) {
+ $taxes = array();
+
+ $regular_tax_rates = $compound_tax_rates = 0;
+
+ foreach ( $rates as $key => $rate )
+ if ( $rate['compound'] == 'yes' )
+ $compound_tax_rates = $compound_tax_rates + $rate['rate'];
+ else
+ $regular_tax_rates = $regular_tax_rates + $rate['rate'];
+
+ $regular_tax_rate = 1 + ( $regular_tax_rates / 100 );
+ $compound_tax_rate = 1 + ( $compound_tax_rates / 100 );
+ $non_compound_price = $price / $compound_tax_rate;
+
+ foreach ( $rates as $key => $rate ) {
+ if ( ! isset( $taxes[ $key ] ) )
+ $taxes[ $key ] = 0;
+
+ $the_rate = $rate['rate'] / 100;
+
+ if ( $rate['compound'] == 'yes' ) {
+ $the_price = $price;
+ $the_rate = $the_rate / $compound_tax_rate;
+ } else {
+ $the_price = $non_compound_price;
+ $the_rate = $the_rate / $regular_tax_rate;
+ }
+
+ $net_price = $price - ( $the_rate * $the_price );
+ $tax_amount = $price - $net_price;
+ $taxes[ $key ] += apply_filters( 'woocommerce_price_inc_tax_amount', $tax_amount, $key, $rate, $price );
+ }
+
+ return $taxes;
+ }
+
+ /**
+ * Calc tax from exclusive price
+ *
+ * @param float $price
+ * @param array $rates
+ * @return array
+ */
+ private function calc_exclusive_tax( $price, $rates ) {
+ $taxes = array();
+
+ // Multiple taxes
+ foreach ( $rates as $key => $rate ) {
+
+ if ( $rate['compound'] == 'yes' )
+ continue;
+
+ $tax_amount = $price * ( $rate['rate'] / 100 );
+
+ // ADVANCED: Allow third parties to modify this rate
+ $tax_amount = apply_filters( 'woocommerce_price_ex_tax_amount', $tax_amount, $key, $rate, $price );
+
+ // Add rate
+ if ( ! isset( $taxes[ $key ] ) )
+ $taxes[ $key ] = $tax_amount;
+ else
+ $taxes[ $key ] += $tax_amount;
+ }
+
+ $pre_compound_total = array_sum( $taxes );
+
+ // Compound taxes
+ if ( $rates ) {
+ foreach ( $rates as $key => $rate ) {
+
+ if ( $rate['compound'] == 'no' )
+ continue;
+
+ $the_price_inc_tax = $price + ( $pre_compound_total * 100 );
+
+ $tax_amount = $the_price_inc_tax * ( $rate['rate'] / 100 );
+
+ // ADVANCED: Allow third parties to modifiy this rate
+ $tax_amount = apply_filters( 'woocommerce_price_ex_tax_amount', $tax_amount, $key, $rate, $price, $the_price_inc_tax, $pre_compound_total );
+
+ // Add rate
+ if ( ! isset( $taxes[ $key ] ) )
+ $taxes[ $key ] = $tax_amount;
+ else
+ $taxes[ $key ] += $tax_amount;
+ }
+ }
+
+ return $taxes;
+ }
+
/**
* Searches for all matching country/state/postcode tax rates.
*
@@ -199,7 +374,6 @@ class WC_Tax {
}
return apply_filters('woocommerce_matched_rates', $matched_tax_rates, $tax_class);
-
}
/**
@@ -361,172 +535,6 @@ class WC_Tax {
return array(); // return false
}
- /**
- * Calculate the tax using a passed array of rates.
- *
- * @param float price
- * @param array rates
- * @param bool passed price includes tax
- * @return array array of rates/amounts
- */
- public function calc_tax( $price, $rates, $price_includes_tax = true ) {
- if ( $price_includes_tax )
- $taxes = $this->calc_inclusive_tax( $price, $rates );
- else
- $taxes = $this->calc_exclusive_tax( $price, $rates );
-
- return apply_filters( 'woocommerce_calc_tax', $taxes, $price, $rates, $price_includes_tax );
- }
-
- /**
- * Calc tax from inclusive price
- *
- * @param float $price
- * @param array $rates
- * @return array
- */
- private function calc_inclusive_tax( $price, $rates ) {
- $taxes = array();
-
- $regular_tax_rates = $compound_tax_rates = 0;
-
- foreach ( $rates as $key => $rate )
- if ( $rate['compound'] == 'yes' )
- $compound_tax_rates = $compound_tax_rates + $rate['rate'];
- else
- $regular_tax_rates = $regular_tax_rates + $rate['rate'];
-
- $regular_tax_rate = 1 + ( $regular_tax_rates / 100 );
- $compound_tax_rate = 1 + ( $compound_tax_rates / 100 );
- $non_compound_price = $price / $compound_tax_rate;
-
- foreach ( $rates as $key => $rate ) {
- if ( ! isset( $taxes[ $key ] ) )
- $taxes[ $key ] = 0;
-
- $the_rate = $rate['rate'] / 100;
-
- if ( $rate['compound'] == 'yes' ) {
- $the_price = $price;
- $the_rate = $the_rate / $compound_tax_rate;
- } else {
- $the_price = $non_compound_price;
- $the_rate = $the_rate / $regular_tax_rate;
- }
-
- $net_price = $price - ( $the_rate * $the_price );
- $net_price = $this->round_at_subtotal ? $net_price : $this->round( $net_price );
- $tax_amount = apply_filters( 'woocommerce_price_inc_tax_amount', $price - $net_price, $key, $rate, $price );
- $taxes[ $key ] += $tax_amount;
- }
- return $taxes;
- }
-
- /**
- * Calc tax from exclusive price
- *
- * @param float $price
- * @param array $rates
- * @return array
- */
- private function calc_exclusive_tax( $price, $rates ) {
- $taxes = array();
- $price = $price * 100; // To avoid float rounding errors, work with integers (pence)
-
- // Multiple taxes
- foreach ( $rates as $key => $rate ) {
-
- if ( $rate['compound'] == 'yes' )
- continue;
-
- $tax_amount = $price * ( $rate['rate'] / 100 );
-
- // ADVANCED: Allow third parties to modify this rate
- $tax_amount = apply_filters( 'woocommerce_price_ex_tax_amount', $tax_amount, $key, $rate, $price );
-
- // Back to pounds
- $tax_amount = ( $tax_amount / 100 );
-
- // Add rate
- if ( ! isset( $taxes[ $key ] ) )
- $taxes[ $key ] = $tax_amount;
- else
- $taxes[ $key ] += $tax_amount;
-
- }
-
- $pre_compound_total = array_sum( $taxes );
-
- // Compound taxes
- if ( $rates ) {
- foreach ( $rates as $key => $rate ) {
-
- if ( $rate['compound'] == 'no' )
- continue;
-
- $the_price_inc_tax = $price + ( $pre_compound_total * 100 );
-
- $tax_amount = $the_price_inc_tax * ( $rate['rate'] / 100 );
-
- // ADVANCED: Allow third parties to modifiy this rate
- $tax_amount = apply_filters( 'woocommerce_price_ex_tax_amount', $tax_amount, $key, $rate, $price, $the_price_inc_tax, $pre_compound_total );
-
- // Back to pounds
- $tax_amount = ( $tax_amount / 100 );
-
- // Add rate
- if ( ! isset( $taxes[ $key ] ) )
- $taxes[ $key ] = $tax_amount;
- else
- $taxes[ $key ] += $tax_amount;
-
- }
- }
-
- return $taxes;
- }
-
- /**
- * Calculate the shipping tax using a passed array of rates.
- *
- * @param int Price
- * @param int Taxation Rate
- * @return int
- */
- public function calc_shipping_tax( $price, $rates ) {
-
- // Taxes array
- $taxes = array();
-
- // Multiple taxes
- foreach ($rates as $key => $rate) :
- if ($rate['compound']=='yes') continue;
-
- $tax_amount = $price * ($rate['rate']/100);
-
- // Add rate
- if (!isset($taxes[$key])) $taxes[$key] = $tax_amount; else $taxes[$key] += $tax_amount;
-
- endforeach;
-
- $pre_compound_total = array_sum($taxes);
-
- // Compound taxes
- foreach ($rates as $key => $rate) :
- if ($rate['compound']=='no') continue;
-
- $the_price_inc_tax = $price + $pre_compound_total;
-
- $tax_amount = $the_price_inc_tax * ($rate['rate']/100);
-
- // Add rate
- if (!isset($taxes[$key])) $taxes[$key] = $tax_amount; else $taxes[$key] += $tax_amount;
-
- endforeach;
-
- return $taxes;
- }
-
/**
* Return true/false depending on if a rate is a compound rate.
*
@@ -586,20 +594,4 @@ class WC_Tax {
public function get_tax_total( $taxes ) {
return array_sum( array_map( array( $this, 'round' ), $taxes ) );
}
-
- /**
- * Round to currency DP. Wrapper for PHP round.
- *
- * Filter example: to return rounding to .5 cents you'd use:
- *
- * public function euro_5cent_rounding( $in ) {
- * return round( $in / 5, 2 ) * 5;
- * }
- * add_filter( 'woocommerce_tax_round', 'euro_5cent_rounding' );
- *
- */
- public function round( $in ) {
- return apply_filters( 'woocommerce_tax_round', round( $in, $this->dp ), $in );
- }
-
}
\ No newline at end of file
diff --git a/includes/class-wc-template-loader.php b/includes/class-wc-template-loader.php
index d5e851727f2..d85395ade07 100644
--- a/includes/class-wc-template-loader.php
+++ b/includes/class-wc-template-loader.php
@@ -41,7 +41,7 @@ class WC_Template_Loader {
$file = 'single-product.php';
$find[] = $file;
- $find[] = WOOCOMMERCE_TEMPLATE_PATH . $file;
+ $find[] = WC_TEMPLATE_PATH . $file;
} elseif ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
@@ -49,15 +49,15 @@ class WC_Template_Loader {
$file = 'taxonomy-' . $term->taxonomy . '.php';
$find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
- $find[] = WOOCOMMERCE_TEMPLATE_PATH . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
+ $find[] = WC_TEMPLATE_PATH . 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.php';
$find[] = $file;
- $find[] = WOOCOMMERCE_TEMPLATE_PATH . $file;
+ $find[] = WC_TEMPLATE_PATH . $file;
} elseif ( is_post_type_archive( 'product' ) || is_page( woocommerce_get_page_id( 'shop' ) ) ) {
$file = 'archive-product.php';
$find[] = $file;
- $find[] = WOOCOMMERCE_TEMPLATE_PATH . $file;
+ $find[] = WC_TEMPLATE_PATH . $file;
}
@@ -81,10 +81,10 @@ class WC_Template_Loader {
if ( get_post_type() !== 'product' )
return $template;
- if ( file_exists( STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_PATH . 'single-product-reviews.php' ))
- return STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_PATH . 'single-product-reviews.php';
- elseif ( file_exists( TEMPLATEPATH . '/' . WOOCOMMERCE_TEMPLATE_PATH . 'single-product-reviews.php' ))
- return TEMPLATEPATH . '/' . WOOCOMMERCE_TEMPLATE_PATH . 'single-product-reviews.php';
+ if ( file_exists( STYLESHEETPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php' ))
+ return STYLESHEETPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php';
+ elseif ( file_exists( TEMPLATEPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php' ))
+ return TEMPLATEPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php';
elseif ( file_exists( STYLESHEETPATH . '/' . 'single-product-reviews.php' ))
return STYLESHEETPATH . '/' . 'single-product-reviews.php';
elseif ( file_exists( TEMPLATEPATH . '/' . 'single-product-reviews.php' ))
diff --git a/includes/gateways/paypal/class-wc-gateway-paypal.php b/includes/gateways/paypal/class-wc-gateway-paypal.php
index eae66cd72a4..427f34893be 100644
--- a/includes/gateways/paypal/class-wc-gateway-paypal.php
+++ b/includes/gateways/paypal/class-wc-gateway-paypal.php
@@ -803,7 +803,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
'sslverify' => false,
'timeout' => 60,
'httpversion' => '1.1',
- 'user-agent' => 'WooCommerce/' . WOOCOMMERCE_VERSION
+ 'user-agent' => 'WooCommerce/' . WC_VERSION
);
// Post back to get a response
diff --git a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php
index 267dd7d8748..aa238807d72 100644
--- a/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php
+++ b/includes/shipping/flat-rate/class-wc-shipping-flat-rate.php
@@ -243,7 +243,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
// Loop options
foreach ( $this->options as $option ) {
- $this_option = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $option ) );
+ $this_option = array_map( 'trim', explode( WC_DELIMITER, $option ) );
if ( sizeof( $this_option ) !== 3 ) continue;
diff --git a/includes/wc-formatting-functions.php b/includes/wc-formatting-functions.php
index 07244e614b2..30b7e640f69 100644
--- a/includes/wc-formatting-functions.php
+++ b/includes/wc-formatting-functions.php
@@ -155,6 +155,24 @@ function woocommerce_trim_zeros( $price ) {
return preg_replace( '/' . preg_quote( get_option( 'woocommerce_price_decimal_sep' ), '/' ) . '0++$/', '', $price );
}
+/**
+ * Round a tax amount
+ *
+ * @access public
+ * @param mixed $price
+ * @return string
+ */
+function woocommerce_round_tax_total( $tax ) {
+ $dp = (int) get_option( 'woocommerce_price_num_decimals' );
+
+ if ( version_compare( phpversion(), '5.3', '<' ) ) {
+ $tax = round( $tax, $dp );
+ } else {
+ $tax = round( $tax, $dp, WC_TAX_ROUNDING_MODE );
+ }
+ return $tax;
+}
+
/**
* Format decimal numbers - format to a defined number of dp and remove trailing zeros.
*
diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php
index c3b44fc0cd1..33a9aba80a4 100644
--- a/includes/wc-template-functions.php
+++ b/includes/wc-template-functions.php
@@ -87,7 +87,7 @@ function wc_setup_product_data( $post ) {
* @return void
*/
function wc_generator_tag() {
- echo "\n\n" . '' . "\n" . '' . "\n\n";
+ echo "\n\n" . '' . "\n" . '' . "\n\n";
}
/**
@@ -1131,7 +1131,7 @@ function wc_cart_totals_order_total_html() {
foreach ( WC()->cart->get_tax_totals() as $code => $tax )
$tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
} else {
- $tax_string_array[] = sprintf( '%s %s', woocommerce_price( WC()->cart->get_taxes_total() ), WC()->countries->tax_or_vat() );
+ $tax_string_array[] = sprintf( '%s %s', woocommerce_price( WC()->cart->get_taxes_total( true, true ) ), WC()->countries->tax_or_vat() );
}
if ( ! empty( $tax_string_array ) )
diff --git a/readme.txt b/readme.txt
index f69fe389750..5ae2f5b064d 100644
--- a/readme.txt
+++ b/readme.txt
@@ -183,7 +183,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Feature - Handling for password protected products.
* Feature - Schema markup selector for downloadables.
* Feature - woocommerce_get_featured_product_ids function.
-* Feature - WOOCOMMERCE_DELIMITER to customise the pipes for attributes
+* Feature - WC_DELIMITER to customise the pipes for attributes
* Feature - Standardized, default credit card form for gateways to use if they support 'default_credit_card_form'.
* Feature - Coupon usage limits per user (using email + ID).
* Tweak - Added pagination to tax rate screens.
diff --git a/templates/single-product/product-attributes.php b/templates/single-product/product-attributes.php
index 5f9538c18cb..77e27b4e0be 100644
--- a/templates/single-product/product-attributes.php
+++ b/templates/single-product/product-attributes.php
@@ -59,7 +59,7 @@ if ( empty( $attributes ) && ( ! $product->enable_dimensions_display() || ( ! $p
} else {
// Convert pipes to commas and display values
- $values = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
+ $values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
}
diff --git a/woocommerce-ajax.php b/woocommerce-ajax.php
index 9a21d4e4246..3be2e036ecc 100644
--- a/woocommerce-ajax.php
+++ b/woocommerce-ajax.php
@@ -454,7 +454,7 @@ function woocommerce_save_attributes() {
// Text based attributes - Posted values are term names - don't change to slugs
} else {
- $values = array_map( 'stripslashes', array_map( 'strip_tags', explode( WOOCOMMERCE_DELIMITER, $attribute_values[ $i ] ) ) );
+ $values = array_map( 'stripslashes', array_map( 'strip_tags', explode( WC_DELIMITER, $attribute_values[ $i ] ) ) );
}
// Remove empty items in the array
@@ -483,7 +483,7 @@ function woocommerce_save_attributes() {
} elseif ( isset( $attribute_values[ $i ] ) ) {
// Text based, separate by pipe
- $values = implode( ' ' . WOOCOMMERCE_DELIMITER . ' ', array_map( 'woocommerce_clean', array_map( 'stripslashes', explode( WOOCOMMERCE_DELIMITER, $attribute_values[ $i ] ) ) ) );
+ $values = implode( ' ' . WC_DELIMITER . ' ', array_map( 'woocommerce_clean', array_map( 'stripslashes', explode( WC_DELIMITER, $attribute_values[ $i ] ) ) ) );
// Custom attribute - Add attribute to array and set the values
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
@@ -635,7 +635,7 @@ function woocommerce_link_all_variations() {
$options[] = $term->slug;
}
} else {
- $options = explode( WOOCOMMERCE_DELIMITER, $attribute['value'] );
+ $options = explode( WC_DELIMITER, $attribute['value'] );
}
$options = array_map( 'sanitize_title', array_map( 'trim', $options ) );
@@ -1219,10 +1219,9 @@ function woocommerce_calc_line_taxes() {
) );
$line_subtotal_taxes = $tax->calc_tax( $line_subtotal, $tax_rates, false );
- $line_taxes = $tax->calc_tax( $line_total, $tax_rates, false );
-
- $line_subtotal_tax = $tax->round( array_sum( $line_subtotal_taxes ) );
- $line_tax = $tax->round( array_sum( $line_taxes ) );
+ $line_taxes = $tax->calc_tax( $line_total, $tax_rates, false );
+ $line_subtotal_tax = array_sum( $line_subtotal_taxes );
+ $line_tax = array_sum( $line_taxes );
if ( $line_subtotal_tax < 0 )
$line_subtotal_tax = 0;
@@ -1295,8 +1294,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'] = $tax->round( isset( $taxes[ $key ] ) ? $taxes[ $key ] : 0 );
- $item['shipping_tax_amount'] = $tax->round( isset( $shipping_taxes[ $key ] ) ? $shipping_taxes[ $key ] : 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 );
if ( ! $item['label'] )
$item['label'] = $woocommerce->countries->tax_or_vat();
diff --git a/woocommerce.php b/woocommerce.php
index 227600ce6ee..6dbc79f4f47 100644
--- a/woocommerce.php
+++ b/woocommerce.php
@@ -122,11 +122,7 @@ final class WooCommerce {
spl_autoload_register( array( $this, 'autoload' ) );
// Define constants
- define( 'WOOCOMMERCE_PLUGIN_FILE', __FILE__ );
- define( 'WOOCOMMERCE_VERSION', $this->version );
- define( 'WOOCOMMERCE_TEMPLATE_PATH', $this->template_path() );
- if ( ! defined( 'WOOCOMMERCE_DELIMITER' ) )
- define( 'WOOCOMMERCE_DELIMITER', '|' );
+ $this->define_constants();
// Include required files
$this->includes();
@@ -157,8 +153,8 @@ final class WooCommerce {
return $this->$key();
else switch( $key ) {
case 'template_url':
- _deprecated_argument( 'Woocommerce->template_url', '2.1', 'WOOCOMMERCE_TEMPLATE_PATH constant' );
- return WOOCOMMERCE_TEMPLATE_PATH;
+ _deprecated_argument( 'Woocommerce->template_url', '2.1', 'WC_TEMPLATE_PATH constant' );
+ return WC_TEMPLATE_PATH;
case 'messages':
_deprecated_argument( 'Woocommerce->messages', '2.1', 'The "messages" field is moved to the messages helper class.' );
return $this->session->get( 'wc_messages', array() );
@@ -247,10 +243,32 @@ final class WooCommerce {
}
}
+ /**
+ * Define WC Constants
+ */
+ private function define_constants() {
+ define( 'WC_PLUGIN_FILE', __FILE__ );
+ define( 'WC_VERSION', $this->version );
+ define( 'WOOCOMMERCE_VERSION', WC_VERSION ); // Backwards compat
+
+ if ( ! defined( 'WC_TEMPLATE_PATH' ) )
+ define( 'WC_TEMPLATE_PATH', $this->template_path() );
+
+ if ( ! defined( 'WC_ROUNDING_PRECISION' ) )
+ define( 'WC_ROUNDING_PRECISION', 4 );
+
+ // 1 = PHP_ROUND_HALF_UP, 2 = PHP_ROUND_HALF_DOWN
+ if ( ! defined( 'WC_TAX_ROUNDING_MODE' ) )
+ define( 'WC_TAX_ROUNDING_MODE', get_option( 'woocommerce_prices_include_tax' ) == 'yes' ? 2 : 1 );
+
+ if ( ! defined( 'WC_DELIMITER' ) )
+ define( 'WC_DELIMITER', '|' );
+ }
+
/**
* Include required core files used in admin and on the frontend.
*/
- public function includes() {
+ private function includes() {
include( 'includes/wc-core-functions.php' );
include( 'includes/class-wc-install.php' );
include( 'includes/class-wc-download-handler.php' );
@@ -483,7 +501,7 @@ final class WooCommerce {
* @return string
*/
public function template_path() {
- return apply_filters( 'woocommerce_template_path', 'woocommerce/' );
+ return apply_filters( 'WC_TEMPLATE_PATH', 'woocommerce/' );
}
/**
| |