Merge branch 'tax-precision'
This commit is contained in:
commit
e50067d68e
|
@ -213,10 +213,10 @@ jQuery( function($){
|
||||||
var line_subtotal_tax = $row.find('input.line_subtotal_tax').val();
|
var line_subtotal_tax = $row.find('input.line_subtotal_tax').val();
|
||||||
|
|
||||||
if ( qty ) {
|
if ( qty ) {
|
||||||
unit_subtotal = accounting.toFixed( ( line_subtotal / qty ), 2 );
|
unit_subtotal = parseFloat( accounting.toFixed( ( line_subtotal / qty ), woocommerce_admin_meta_boxes.rounding_precision ) );
|
||||||
unit_subtotal_tax = accounting.toFixed( ( line_subtotal_tax / qty ), 2 );
|
unit_subtotal_tax = parseFloat( accounting.toFixed( ( line_subtotal_tax / qty ), woocommerce_admin_meta_boxes.rounding_precision ) );
|
||||||
unit_total = accounting.toFixed( ( line_total / qty ), 2 );
|
unit_total = parseFloat( accounting.toFixed( ( line_total / qty ), woocommerce_admin_meta_boxes.rounding_precision ) );
|
||||||
unit_total_tax = accounting.toFixed( ( line_tax / qty ), 2 );
|
unit_total_tax = parseFloat( accounting.toFixed( ( line_tax / qty ), woocommerce_admin_meta_boxes.rounding_precision ) );
|
||||||
} else {
|
} else {
|
||||||
unit_subtotal = unit_subtotal_tax = unit_total = unit_total_tax = 0;
|
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 unit_total_tax = $row.attr('data-unit_total_tax');
|
||||||
var o_qty = $(this).attr('data-o_qty');
|
var o_qty = $(this).attr('data-o_qty');
|
||||||
|
|
||||||
var subtotal = accounting.formatNumber( unit_subtotal * qty, 2, '' );
|
var subtotal = parseFloat( accounting.formatNumber( unit_subtotal * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) );
|
||||||
var tax = accounting.formatNumber( unit_subtotal_tax * qty, 2, '' );
|
var tax = parseFloat( accounting.formatNumber( unit_subtotal_tax * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) );
|
||||||
var total = accounting.formatNumber( unit_total * qty, 2, '' );
|
var total = parseFloat( accounting.formatNumber( unit_total * qty, woocommerce_admin_meta_boxes.rounding_precision, '' ) );
|
||||||
var total_tax = accounting.formatNumber( unit_total_tax * qty, 2, '' );
|
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_subtotal').val( subtotal );
|
||||||
$row.find('input.line_total').val( total );
|
$row.find('input.line_total').val( total );
|
||||||
|
@ -270,7 +270,7 @@ jQuery( function($){
|
||||||
var $row = $(this).closest('tr.item');
|
var $row = $(this).closest('tr.item');
|
||||||
var $qty = $row.find('input.quantity');
|
var $qty = $row.find('input.quantity');
|
||||||
var qty = $qty.val();
|
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 );
|
$row.attr( 'data-unit_subtotal', value );
|
||||||
});
|
});
|
||||||
|
@ -280,7 +280,7 @@ jQuery( function($){
|
||||||
var $row = $(this).closest('tr.item');
|
var $row = $(this).closest('tr.item');
|
||||||
var $qty = $row.find('input.quantity');
|
var $qty = $row.find('input.quantity');
|
||||||
var qty = $qty.val();
|
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 );
|
$row.attr( 'data-unit_total', value );
|
||||||
});
|
});
|
||||||
|
@ -290,7 +290,7 @@ jQuery( function($){
|
||||||
var $row = $(this).closest('tr.item');
|
var $row = $(this).closest('tr.item');
|
||||||
var $qty = $row.find('input.quantity');
|
var $qty = $row.find('input.quantity');
|
||||||
var qty = $qty.val();
|
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 );
|
$row.attr( 'data-unit_subtotal_tax', value );
|
||||||
});
|
});
|
||||||
|
@ -300,7 +300,7 @@ jQuery( function($){
|
||||||
var $row = $(this).closest('tr.item');
|
var $row = $(this).closest('tr.item');
|
||||||
var $qty = $row.find('input.quantity');
|
var $qty = $row.find('input.quantity');
|
||||||
var qty = $qty.val();
|
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 );
|
$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() {
|
$('#woocommerce-order-totals').on( 'change input', '.order_taxes_amount, .order_taxes_shipping_amount, .shipping_cost, #_order_discount', function() {
|
||||||
|
|
||||||
var $this = $(this);
|
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;
|
var total = 0;
|
||||||
|
|
||||||
fields.each(function(){
|
fields.each(function(){
|
||||||
|
@ -317,6 +317,10 @@ jQuery( function($){
|
||||||
total = total + parseFloat( $(this).val() );
|
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, {
|
var formatted_total = accounting.formatMoney( total, {
|
||||||
symbol : woocommerce_admin_meta_boxes.currency_format_symbol,
|
symbol : woocommerce_admin_meta_boxes.currency_format_symbol,
|
||||||
decimal : woocommerce_admin_meta_boxes.currency_format_decimal_sep,
|
decimal : woocommerce_admin_meta_boxes.currency_format_decimal_sep,
|
||||||
|
@ -381,7 +385,7 @@ jQuery( function($){
|
||||||
|
|
||||||
order_shipping = 0;
|
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 = $(this).val() || '0';
|
||||||
cost = accounting.unformat( cost.replace(',', '.') );
|
cost = accounting.unformat( cost.replace(',', '.') );
|
||||||
order_shipping = order_shipping + parseFloat( cost );
|
order_shipping = order_shipping + parseFloat( cost );
|
||||||
|
@ -445,13 +449,13 @@ jQuery( function($){
|
||||||
|
|
||||||
order_discount = accounting.unformat( order_discount.replace(',', '.') );
|
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 = $(this).val() || '0';
|
||||||
cost = accounting.unformat( cost.replace(',', '.') );
|
cost = accounting.unformat( cost.replace(',', '.') );
|
||||||
shipping = shipping + parseFloat( cost );
|
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 = $(this).val() || '0';
|
||||||
cost = accounting.unformat( cost.replace(',', '.') );
|
cost = accounting.unformat( cost.replace(',', '.') );
|
||||||
tax = tax + parseFloat( cost );
|
tax = tax + parseFloat( cost );
|
||||||
|
@ -464,10 +468,10 @@ jQuery( function($){
|
||||||
|
|
||||||
// Tax
|
// Tax
|
||||||
if ( woocommerce_admin_meta_boxes.round_at_subtotal == 'yes' )
|
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
|
// 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();
|
$('#woocommerce-order-totals').unblock();
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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;
|
||||||
|
}
|
|
@ -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};
|
|
@ -769,7 +769,7 @@ class WC_Product {
|
||||||
$tax_rates = $_tax->get_rates( $this->get_tax_class() );
|
$tax_rates = $_tax->get_rates( $this->get_tax_class() );
|
||||||
$taxes = $_tax->calc_tax( $price * $qty, $tax_rates, false );
|
$taxes = $_tax->calc_tax( $price * $qty, $tax_rates, false );
|
||||||
$tax_amount = $_tax->get_tax_total( $taxes );
|
$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 {
|
} else {
|
||||||
|
|
||||||
|
@ -780,13 +780,13 @@ class WC_Product {
|
||||||
|
|
||||||
$base_taxes = $_tax->calc_tax( $price * $qty, $base_tax_rates, true );
|
$base_taxes = $_tax->calc_tax( $price * $qty, $base_tax_rates, true );
|
||||||
$base_tax_amount = array_sum( $base_taxes );
|
$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 ) {
|
} elseif ( $tax_rates !== $base_tax_rates ) {
|
||||||
|
|
||||||
$base_taxes = $_tax->calc_tax( $price * $qty, $base_tax_rates, true );
|
$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 );
|
$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 {
|
} else {
|
||||||
|
|
||||||
|
|
|
@ -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( '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 );
|
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_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_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
|
'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' ) ) ),
|
'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_visibility' => apply_filters( 'default_attribute_visibility', false ),
|
||||||
'default_attribute_variation' => apply_filters( 'default_attribute_variation', false ),
|
'default_attribute_variation' => apply_filters( 'default_attribute_variation', false ),
|
||||||
|
|
|
@ -29,7 +29,7 @@ class WC_Admin_Notices {
|
||||||
*/
|
*/
|
||||||
public function add_notices() {
|
public function add_notices() {
|
||||||
if ( get_option( '_wc_needs_update' ) == 1 || get_option( '_wc_needs_pages' ) == 1 ) {
|
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' ) );
|
add_action( 'admin_notices', array( $this, 'install_notice' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class WC_Admin_Notices {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( get_option( 'woocommerce_theme_support_check' ) !== $template ) {
|
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' ) );
|
add_action( 'admin_notices', array( $this, 'theme_check_notice' ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ class WC_Admin_Welcome {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function admin_css() {
|
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 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -269,8 +269,8 @@ class WC_Meta_Box_Order_Totals {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update totals
|
// Update totals
|
||||||
update_post_meta( $post_id, '_order_tax', woocommerce_format_decimal( $total_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( $total_shipping_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_discount', woocommerce_format_decimal( $_POST['_order_discount'], false ) );
|
||||||
update_post_meta( $post_id, '_order_total', woocommerce_format_decimal( $_POST['_order_total'], false ) );
|
update_post_meta( $post_id, '_order_total', woocommerce_format_decimal( $_POST['_order_total'], false ) );
|
||||||
|
|
||||||
|
|
|
@ -469,7 +469,7 @@ class WC_Meta_Box_Product_Data {
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach ( $post_terms as $term )
|
foreach ( $post_terms as $term )
|
||||||
$values[] = $term->name;
|
$values[] = $term->name;
|
||||||
echo esc_attr( implode( ' ' . WOOCOMMERCE_DELIMITER . ' ', $values ) );
|
echo esc_attr( implode( ' ' . WC_DELIMITER . ' ', $values ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
?>" placeholder="<?php _e( 'Pipe (|) separate terms', 'woocommerce' ); ?>" />
|
?>" placeholder="<?php _e( 'Pipe (|) separate terms', 'woocommerce' ); ?>" />
|
||||||
|
@ -898,7 +898,7 @@ class WC_Meta_Box_Product_Data {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$options = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
|
$options = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
|
||||||
|
|
||||||
foreach ( $options as $option )
|
foreach ( $options as $option )
|
||||||
echo '<option ' . selected( sanitize_title( $variation_selected_value ), sanitize_title( $option ), false ) . ' value="' . esc_attr( sanitize_title( $option ) ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
|
echo '<option ' . selected( sanitize_title( $variation_selected_value ), sanitize_title( $option ), false ) . ' value="' . esc_attr( sanitize_title( $option ) ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
|
||||||
|
@ -1036,7 +1036,7 @@ class WC_Meta_Box_Product_Data {
|
||||||
|
|
||||||
// Text based attributes - Posted values are term names - don't change to slugs
|
// Text based attributes - Posted values are term names - don't change to slugs
|
||||||
} else {
|
} 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
|
// Remove empty items in the array
|
||||||
|
@ -1065,7 +1065,7 @@ class WC_Meta_Box_Product_Data {
|
||||||
} elseif ( isset( $attribute_values[ $i ] ) ) {
|
} elseif ( isset( $attribute_values[ $i ] ) ) {
|
||||||
|
|
||||||
// Text based, separate by pipe
|
// 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
|
// Custom attribute - Add attribute to array and set the values
|
||||||
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
|
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
|
||||||
|
|
|
@ -56,7 +56,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
<td class="line_cost" width="1%">
|
<td class="line_cost" width="1%">
|
||||||
<div class="view">
|
<div class="view">
|
||||||
<?php if ( isset( $item['line_total'] ) ) echo woocommerce_price( $item['line_tax'] ); ?>
|
<?php if ( isset( $item['line_total'] ) ) echo woocommerce_price( woocommerce_round_tax_total( $item['line_tax'] ) ); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="edit" style="display:none">
|
<div class="edit" style="display:none">
|
||||||
<label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_total'] ) ) echo esc_attr( $item['line_total'] ); ?>" class="line_total wc_input_decimal" /></label>
|
<label><?php _e( 'Total', 'woocommerce' ); ?>: <input type="text" name="line_total[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_total'] ) ) echo esc_attr( $item['line_total'] ); ?>" class="line_total wc_input_decimal" /></label>
|
||||||
|
@ -67,7 +67,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
<td class="line_tax" width="1%">
|
<td class="line_tax" width="1%">
|
||||||
<div class="view">
|
<div class="view">
|
||||||
<?php if ( isset( $item['line_tax'] ) ) echo woocommerce_price( $item['line_tax'] ); ?>
|
<?php if ( isset( $item['line_tax'] ) ) echo woocommerce_price( woocommerce_round_tax_total( $item['line_tax'] ) ); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="edit" style="display:none">
|
<div class="edit" style="display:none">
|
||||||
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_tax'] ) ) echo esc_attr( $item['line_tax'] ); ?>" class="line_tax wc_input_decimal" />
|
<input type="text" name="line_tax[<?php echo absint( $item_id ); ?>]" placeholder="0.00" value="<?php if ( isset( $item['line_tax'] ) ) echo esc_attr( $item['line_tax'] ); ?>" class="line_tax wc_input_decimal" />
|
||||||
|
|
|
@ -176,9 +176,9 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
<div class="view">
|
<div class="view">
|
||||||
<?php
|
<?php
|
||||||
if ( isset( $item['line_tax'] ) ) {
|
if ( isset( $item['line_tax'] ) ) {
|
||||||
if ( isset( $item['line_subtotal_tax'] ) && $item['line_subtotal_tax'] != $item['line_tax'] ) echo '<del>' . woocommerce_price( $item['line_subtotal_tax'] ) . '</del> ';
|
if ( isset( $item['line_subtotal_tax'] ) && $item['line_subtotal_tax'] != $item['line_tax'] ) echo '<del>' . woocommerce_price( woocommerce_round_tax_total( $item['line_subtotal_tax'] ) ) . '</del> ';
|
||||||
|
|
||||||
echo woocommerce_price( $item['line_tax'] );
|
echo woocommerce_price( woocommerce_round_tax_total( $item['line_tax'] ) );
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -30,7 +30,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$options = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
|
$options = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
|
||||||
|
|
||||||
foreach ( $options as $option ) {
|
foreach ( $options as $option ) {
|
||||||
echo '<option ' . selected( sanitize_title( $variation_selected_value ), sanitize_title( $option ), false ) . ' value="' . esc_attr( sanitize_title( $option ) ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
|
echo '<option ' . selected( sanitize_title( $variation_selected_value ), sanitize_title( $option ), false ) . ' value="' . esc_attr( sanitize_title( $option ) ) . '">' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
|
||||||
|
|
|
@ -72,13 +72,13 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
|
||||||
'tax_amount' => array(
|
'tax_amount' => array(
|
||||||
'type' => 'order_item_meta',
|
'type' => 'order_item_meta',
|
||||||
'order_item_type' => 'tax',
|
'order_item_type' => 'tax',
|
||||||
'function' => 'SUM',
|
'function' => '',
|
||||||
'name' => 'tax_amount'
|
'name' => 'tax_amount'
|
||||||
),
|
),
|
||||||
'shipping_tax_amount' => array(
|
'shipping_tax_amount' => array(
|
||||||
'type' => 'order_item_meta',
|
'type' => 'order_item_meta',
|
||||||
'order_item_type' => 'tax',
|
'order_item_type' => 'tax',
|
||||||
'function' => 'SUM',
|
'function' => '',
|
||||||
'name' => 'shipping_tax_amount'
|
'name' => 'shipping_tax_amount'
|
||||||
),
|
),
|
||||||
'rate_id' => array(
|
'rate_id' => array(
|
||||||
|
@ -86,13 +86,7 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
|
||||||
'order_item_type' => 'tax',
|
'order_item_type' => 'tax',
|
||||||
'function' => '',
|
'function' => '',
|
||||||
'name' => 'rate_id'
|
'name' => 'rate_id'
|
||||||
),
|
)
|
||||||
'ID' => array(
|
|
||||||
'type' => 'post_data',
|
|
||||||
'function' => 'COUNT',
|
|
||||||
'name' => 'total_orders',
|
|
||||||
'distinct' => true,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'where' => array(
|
'where' => array(
|
||||||
array(
|
array(
|
||||||
|
@ -106,7 +100,6 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
|
||||||
'operator' => '!='
|
'operator' => '!='
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
'group_by' => 'tax_rate',
|
|
||||||
'order_by' => 'post_date ASC',
|
'order_by' => 'post_date ASC',
|
||||||
'query_type' => 'get_results',
|
'query_type' => 'get_results',
|
||||||
'filter_range' => true
|
'filter_range' => true
|
||||||
|
@ -127,15 +120,32 @@ class WC_Report_Taxes_By_Code extends WC_Admin_Report {
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row" colspan="3"><?php _e( 'Total', 'woocommerce' ); ?></th>
|
<th scope="row" colspan="3"><?php _e( 'Total', 'woocommerce' ); ?></th>
|
||||||
<th class="total_row"><?php echo woocommerce_price( array_sum( wp_list_pluck( (array) $tax_rows, 'tax_amount' ) ) ); ?></th>
|
<th class="total_row"><?php echo woocommerce_price( woocommerce_round_tax_total( array_sum( wp_list_pluck( (array) $tax_rows, 'tax_amount' ) ) ) ); ?></th>
|
||||||
<th class="total_row"><?php echo woocommerce_price( array_sum( wp_list_pluck( (array) $tax_rows, 'shipping_tax_amount' ) ) ); ?></th>
|
<th class="total_row"><?php echo woocommerce_price( woocommerce_round_tax_total( array_sum( wp_list_pluck( (array) $tax_rows, 'shipping_tax_amount' ) ) ) ); ?></th>
|
||||||
<th class="total_row"><strong><?php echo woocommerce_price( array_sum( wp_list_pluck( (array) $tax_rows, 'tax_amount' ) ) + array_sum( wp_list_pluck( (array) $tax_rows, 'shipping_tax_amount' ) ) ); ?></strong></th>
|
<th class="total_row"><strong><?php echo woocommerce_price( woocommerce_round_tax_total( array_sum( wp_list_pluck( (array) $tax_rows, 'tax_amount' ) ) + array_sum( wp_list_pluck( (array) $tax_rows, 'shipping_tax_amount' ) ) ) ); ?></strong></th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php
|
<?php
|
||||||
|
$grouped_tax_tows = array();
|
||||||
|
|
||||||
foreach ( $tax_rows as $tax_row ) {
|
foreach ( $tax_rows as $tax_row ) {
|
||||||
$rate = $wpdb->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 ) );
|
||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><?php echo $tax_row->tax_rate; ?></th>
|
<th scope="row"><?php echo $tax_row->tax_rate; ?></th>
|
||||||
|
|
|
@ -677,21 +677,6 @@ class WC_Cart {
|
||||||
return apply_filters( 'woocommerce_cart_get_taxes', $taxes, $this );
|
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.
|
* 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 ]->is_compound = $this->tax->is_compound( $key );
|
||||||
$tax_totals[ $code ]->label = $this->tax->get_rate_label( $key );
|
$tax_totals[ $code ]->label = $this->tax->get_rate_label( $key );
|
||||||
$tax_totals[ $code ]->amount += $tax;
|
$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 );
|
return apply_filters( 'woocommerce_cart_tax_totals', $tax_totals, $this );
|
||||||
|
@ -967,260 +952,227 @@ class WC_Cart {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get count of all items + weights + subtotal (we may need this for discounts)
|
|
||||||
$subtotal = 0;
|
|
||||||
$subtotal_tax = 0;
|
|
||||||
$tax_rates = array();
|
$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 ) {
|
foreach ( $this->get_cart() as $cart_item_key => $values ) {
|
||||||
|
|
||||||
$_product = $values['data'];
|
$_product = $values['data'];
|
||||||
|
|
||||||
// Count items + weight
|
// Count items + weight
|
||||||
$this->cart_contents_weight = $this->cart_contents_weight + ( $_product->get_weight() * $values['quantity'] );
|
$this->cart_contents_weight += $_product->get_weight() * $values['quantity'];
|
||||||
$this->cart_contents_count = $this->cart_contents_count + $values['quantity'];
|
$this->cart_contents_count += $values['quantity'];
|
||||||
|
|
||||||
// Line price
|
// Prices
|
||||||
$line_price = $_product->get_price() * $values['quantity'];
|
$base_price = $_product->get_price();
|
||||||
|
$line_price = $_product->get_price() * $values['quantity'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No tax to calculate
|
||||||
|
*/
|
||||||
if ( ! $_product->is_taxable() ) {
|
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
|
// Get base tax rates
|
||||||
if ( empty( $shop_tax_rates[ $_product->tax_class ] ) )
|
if ( empty( $shop_tax_rates[ $_product->tax_class ] ) )
|
||||||
$shop_tax_rates[ $_product->tax_class ] = $this->tax->get_shop_base_rate( $_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
|
// Get item tax rates
|
||||||
if ( empty( $tax_rates[ $_product->get_tax_class() ] ) )
|
if ( empty( $tax_rates[ $_product->get_tax_class() ] ) )
|
||||||
$tax_rates[ $_product->get_tax_class() ] = $this->tax->get_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() ];
|
$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)
|
// Work out a new base price without the shop's base tax
|
||||||
if ( $item_tax_rates !== $base_tax_rates ) {
|
$taxes = $this->tax->calc_tax( $line_price, $base_tax_rates, true, true );
|
||||||
// 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 = $line_price - array_sum( $taxes );
|
||||||
// Now we have a new item price (excluding TAX)
|
|
||||||
$line_price = $this->tax->round( $line_price - $line_tax );
|
// Now add modifed taxes
|
||||||
|
$tax_result = $this->tax->calc_tax( $line_subtotal, $item_tax_rates );
|
||||||
// Now add taxes for the users location
|
$line_subtotal_tax = array_sum( $taxes );
|
||||||
$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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regular tax calculation (customer inside base and the tax class is unmodified
|
||||||
|
*/
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if ( $_product->is_taxable() ) {
|
// Calc tax normally
|
||||||
$taxes = $this->tax->calc_tax( $line_price, $item_tax_rates, false );
|
$taxes = $this->tax->calc_tax( $line_price, $item_tax_rates, true );
|
||||||
$line_tax = $this->round_at_subtotal ? array_sum( $taxes ) : $this->tax->get_tax_total( $taxes );
|
$line_subtotal_tax = array_sum( $taxes );
|
||||||
$subtotal_tax += $line_tax;
|
$line_subtotal = $line_price - array_sum( $taxes );
|
||||||
}
|
|
||||||
|
|
||||||
$subtotal += $line_price;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$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() );
|
||||||
|
|
||||||
/**
|
$item_tax_rates = $tax_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'];
|
|
||||||
|
|
||||||
// Prices
|
// Base tax for line before discount - we will store this in the order data
|
||||||
$base_price = $_product->get_price();
|
$taxes = $this->tax->calc_tax( $line_price, $item_tax_rates );
|
||||||
$line_price = $_product->get_price() * $values['quantity'];
|
$line_subtotal_tax = array_sum( $taxes );
|
||||||
|
$line_subtotal = $line_price;
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} 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
|
* ADJUST TAX - Calculations when base tax is not equal to the item tax
|
||||||
*
|
|
||||||
* This calculation is simpler - work with the base, untaxed price.
|
|
||||||
*/
|
*/
|
||||||
$_product = $values['data'];
|
if ( $item_tax_rates !== $base_tax_rates ) {
|
||||||
|
|
||||||
// Prices
|
// Work out a new base price without the shop's base tax
|
||||||
$base_price = $_product->get_price();
|
$taxes = $this->tax->calc_tax( $line_price, $base_tax_rates, true, true );
|
||||||
$line_price = $_product->get_price() * $values['quantity'];
|
|
||||||
|
// 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 );
|
* Regular tax calculation (customer inside base and the tax class is unmodified
|
||||||
|
*/
|
||||||
// Taxes
|
|
||||||
if ( ! $_product->is_taxable() ) {
|
|
||||||
$discounted_tax_amount = 0;
|
|
||||||
$line_subtotal_tax = 0;
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Get item tax rates
|
// Work out a new base price without the shop's base tax
|
||||||
if ( empty( $tax_rates[ $_product->get_tax_class() ] ) )
|
$taxes = $this->tax->calc_tax( $line_price, $item_tax_rates, true );
|
||||||
$tax_rates[ $_product->get_tax_class() ] = $this->tax->get_rates( $_product->get_tax_class() );
|
|
||||||
|
// 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() ];
|
// Calc prices and tax (discounted)
|
||||||
|
$discounted_price = $this->get_discounted_price( $values, $base_price, true );
|
||||||
// Base tax for line before discount - we will store this in the order data
|
$discounted_taxes = $this->tax->calc_tax( $discounted_price * $values['quantity'], $item_tax_rates, true );
|
||||||
$line_subtotal_tax = array_sum( $this->tax->calc_tax( $line_price, $item_tax_rates, false ) );
|
$line_tax = array_sum( $discounted_taxes );
|
||||||
|
$line_total = ( $discounted_price * $values['quantity'] ) - $line_tax;
|
||||||
// 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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Line prices
|
// Tax rows - merge the totals we just got
|
||||||
$line_tax = $discounted_tax_amount;
|
foreach ( array_keys( $this->taxes + $discounted_taxes ) as $key ) {
|
||||||
$line_subtotal = $line_price;
|
$this->taxes[ $key ] = ( isset( $discounted_taxes[ $key ] ) ? $discounted_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
|
||||||
$line_total = $discounted_price * $values['quantity'];
|
}
|
||||||
|
|
||||||
// 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
|
// Tax rows - merge the totals we just got
|
||||||
$this->cart_contents_total = $this->cart_contents_total + $line_total;
|
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 );
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
// 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
|
// Trigger the fees API where developers can add fees to the cart
|
||||||
$this->calculate_fees();
|
$this->calculate_fees();
|
||||||
|
|
||||||
// Total up/round taxes
|
// Total up/round taxes and shipping taxes
|
||||||
if ( $this->round_at_subtotal ) {
|
if ( $this->round_at_subtotal ) {
|
||||||
$this->tax_total = $this->tax->get_tax_total( $this->taxes );
|
$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->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 );
|
$this->shipping_taxes = array_map( array( $this->tax, 'round' ), $this->shipping_taxes );
|
||||||
} else {
|
} else {
|
||||||
|
$this->tax_total = array_sum( $this->taxes );
|
||||||
$this->shipping_tax_total = array_sum( $this->shipping_taxes );
|
$this->shipping_tax_total = array_sum( $this->shipping_taxes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1870,13 +1817,11 @@ class WC_Cart {
|
||||||
// Get tax rates
|
// Get tax rates
|
||||||
$tax_rates = $this->tax->get_rates( $fee->tax_class );
|
$tax_rates = $this->tax->get_rates( $fee->tax_class );
|
||||||
$fee_taxes = $this->tax->calc_tax( $fee->amount, $tax_rates, false );
|
$fee_taxes = $this->tax->calc_tax( $fee->amount, $tax_rates, false );
|
||||||
|
$fee->tax = $fee_taxes['total_tax'];
|
||||||
// Store
|
|
||||||
$fee->tax = array_sum( $fee_taxes );
|
|
||||||
|
|
||||||
// Tax rows - merge the totals we just got
|
// Tax rows - merge the totals we just got
|
||||||
foreach ( array_keys( $this->taxes + $fee_taxes ) as $key ) {
|
foreach ( array_keys( $this->taxes + $fee_taxes['taxes'] ) as $key ) {
|
||||||
$this->taxes[ $key ] = ( isset( $fee_taxes[ $key ] ) ? $fee_taxes[ $key ] : 0 ) + ( isset( $this->taxes[ $key ] ) ? $this->taxes[ $key ] : 0 );
|
$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)
|
// cart + shipping + non-compound taxes (after discount)
|
||||||
if ( $compound ) {
|
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)
|
// Otherwise we show cart items totals only (before discount)
|
||||||
} else {
|
} else {
|
||||||
|
@ -2057,10 +2002,11 @@ class WC_Cart {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get tax row amounts with or without compound taxes includes.
|
* 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
|
* @return float price
|
||||||
*/
|
*/
|
||||||
public function get_taxes_total( $compound = true ) {
|
public function get_taxes_total( $compound = true, $display = true ) {
|
||||||
$total = 0;
|
$total = 0;
|
||||||
foreach ( $this->taxes as $key => $tax ) {
|
foreach ( $this->taxes as $key => $tax ) {
|
||||||
if ( ! $compound && $this->tax->is_compound( $key ) ) continue;
|
if ( ! $compound && $this->tax->is_compound( $key ) ) continue;
|
||||||
|
@ -2070,7 +2016,10 @@ class WC_Cart {
|
||||||
if ( ! $compound && $this->tax->is_compound( $key ) ) continue;
|
if ( ! $compound && $this->tax->is_compound( $key ) ) continue;
|
||||||
$total += $tax;
|
$total += $tax;
|
||||||
}
|
}
|
||||||
return $total;
|
if ( $display )
|
||||||
|
return woocommerce_round_tax_total( $total );
|
||||||
|
else
|
||||||
|
return $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -80,8 +80,6 @@ class WC_Checkout {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct () {
|
public function __construct () {
|
||||||
global $woocommerce;
|
|
||||||
|
|
||||||
add_action( 'woocommerce_checkout_billing', array( $this,'checkout_form_billing' ) );
|
add_action( 'woocommerce_checkout_billing', array( $this,'checkout_form_billing' ) );
|
||||||
add_action( 'woocommerce_checkout_shipping', array( $this,'checkout_form_shipping' ) );
|
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;
|
$this->must_create_account = $this->enable_guest_checkout || is_user_logged_in() ? false : true;
|
||||||
|
|
||||||
// Define all Checkout fields
|
// Define all Checkout fields
|
||||||
$this->checkout_fields['billing'] = $woocommerce->countries->get_address_fields( $this->get_value('billing_country'), 'billing_' );
|
$this->checkout_fields['billing'] = WC()->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['shipping'] = WC()->countries->get_address_fields( $this->get_value('shipping_country'), 'shipping_' );
|
||||||
|
|
||||||
if ( get_option( 'woocommerce_registration_generate_username' ) == 'no' ) {
|
if ( get_option( 'woocommerce_registration_generate_username' ) == 'no' ) {
|
||||||
$this->checkout_fields['account']['account_username'] = array(
|
$this->checkout_fields['account']['account_username'] = array(
|
||||||
|
@ -164,7 +162,7 @@ class WC_Checkout {
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function create_order() {
|
public function create_order() {
|
||||||
global $woocommerce, $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
// Give plugins the opportunity to create an order themselves
|
// Give plugins the opportunity to create an order themselves
|
||||||
$order_id = apply_filters( 'woocommerce_create_order', null, $this );
|
$order_id = apply_filters( 'woocommerce_create_order', null, $this );
|
||||||
|
@ -186,9 +184,9 @@ class WC_Checkout {
|
||||||
// Insert or update the post data
|
// Insert or update the post data
|
||||||
$create_new_order = true;
|
$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 */
|
/* Check order is unpaid by getting its status */
|
||||||
$terms = wp_get_object_terms( $order_id, 'shop_order_status', array( 'fields' => 'slugs' ) );
|
$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 ] );
|
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 ) {
|
foreach ( $this->checkout_fields['shipping'] as $key => $field ) {
|
||||||
$postvalue = false;
|
$postvalue = false;
|
||||||
|
|
||||||
|
@ -255,7 +253,7 @@ class WC_Checkout {
|
||||||
do_action( 'woocommerce_checkout_update_user_meta', $this->customer_id, $this->posted );
|
do_action( 'woocommerce_checkout_update_user_meta', $this->customer_id, $this->posted );
|
||||||
|
|
||||||
// Store the line items to the new/resumed order
|
// 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'];
|
$_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, '_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, '_product_id', $values['product_id'] );
|
||||||
woocommerce_add_order_item_meta( $item_id, '_variation_id', $values['variation_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_subtotal', woocommerce_format_decimal( $values['line_subtotal'], false ) );
|
||||||
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'], 4 ) );
|
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'], 4 ) );
|
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'], 4 ) );
|
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
|
// Store variation data in meta so admin can view it
|
||||||
if ( $values['variation'] && is_array( $values['variation'] ) )
|
if ( $values['variation'] && is_array( $values['variation'] ) )
|
||||||
|
@ -291,7 +289,7 @@ class WC_Checkout {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store fees
|
// 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(
|
$item_id = woocommerce_add_order_item( $order_id, array(
|
||||||
'order_item_name' => $fee->name,
|
'order_item_name' => $fee->name,
|
||||||
'order_item_type' => 'fee'
|
'order_item_type' => 'fee'
|
||||||
|
@ -302,8 +300,8 @@ class WC_Checkout {
|
||||||
else
|
else
|
||||||
woocommerce_add_order_item_meta( $item_id, '_tax_class', '0' );
|
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_total', woocommerce_format_decimal( $fee->amount, false ) );
|
||||||
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $fee->tax ) );
|
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $fee->tax, false ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store shipping for all packages
|
// Store shipping for all packages
|
||||||
|
@ -321,31 +319,31 @@ class WC_Checkout {
|
||||||
|
|
||||||
if ( $item_id ) {
|
if ( $item_id ) {
|
||||||
woocommerce_add_order_item_meta( $item_id, 'method_id', $method->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
|
// 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(
|
$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'
|
'order_item_type' => 'tax'
|
||||||
) );
|
) );
|
||||||
|
|
||||||
// Add line item meta
|
// Add line item meta
|
||||||
if ( $item_id ) {
|
if ( $item_id ) {
|
||||||
woocommerce_add_order_item_meta( $item_id, 'rate_id', $key );
|
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, 'label', WC()->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, 'compound', absint( WC()->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, '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( $woocommerce->cart->shipping_taxes[ $key ] ) ? $woocommerce->cart->shipping_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
|
// Store coupons
|
||||||
if ( $applied_coupons = $woocommerce->cart->get_coupons() ) {
|
if ( $applied_coupons = WC()->cart->get_coupons() ) {
|
||||||
foreach ( $applied_coupons as $code => $coupon ) {
|
foreach ( $applied_coupons as $code => $coupon ) {
|
||||||
|
|
||||||
$item_id = woocommerce_add_order_item( $order_id, array(
|
$item_id = woocommerce_add_order_item( $order_id, array(
|
||||||
|
@ -355,7 +353,7 @@ class WC_Checkout {
|
||||||
|
|
||||||
// Add line item meta
|
// Add line item meta
|
||||||
if ( $item_id ) {
|
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', $this->payment_method->id );
|
||||||
update_post_meta( $order_id, '_payment_method_title', $this->payment_method->get_title() );
|
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_shipping', woocommerce_format_decimal( WC()->cart->shipping_total, false ) );
|
||||||
update_post_meta( $order_id, '_order_discount', woocommerce_format_decimal( $woocommerce->cart->get_order_discount_total() ) );
|
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( $woocommerce->cart->get_cart_discount_total() ) );
|
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->cart->tax_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->cart->shipping_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( $woocommerce->cart->total ) );
|
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, '_order_key', apply_filters('woocommerce_generate_order_key', uniqid('order_') ) );
|
||||||
update_post_meta( $order_id, '_customer_user', absint( $this->customer_id ) );
|
update_post_meta( $order_id, '_customer_user', absint( $this->customer_id ) );
|
||||||
|
@ -394,7 +392,7 @@ class WC_Checkout {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function process_checkout() {
|
public function process_checkout() {
|
||||||
global $wpdb, $woocommerce, $current_user;
|
global $wpdb, $current_user;
|
||||||
|
|
||||||
wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-process_checkout' );
|
wp_verify_nonce( $_POST['_wpnonce'], 'woocommerce-process_checkout' );
|
||||||
|
|
||||||
|
@ -406,7 +404,7 @@ class WC_Checkout {
|
||||||
|
|
||||||
do_action( 'woocommerce_before_checkout_process' );
|
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. <a href="%s">Return to homepage →</a>', 'woocommerce' ), home_url() ) );
|
wc_add_error( sprintf( __( 'Sorry, your session has expired. <a href="%s">Return to homepage →</a>', 'woocommerce' ), home_url() ) );
|
||||||
|
|
||||||
do_action( 'woocommerce_checkout_process' );
|
do_action( 'woocommerce_checkout_process' );
|
||||||
|
@ -425,7 +423,7 @@ class WC_Checkout {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ship to billing only option
|
// 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;
|
$this->posted['ship_to_different_address'] = false;
|
||||||
|
|
||||||
// Update customer shipping and payment method to posted method
|
// Update customer shipping and payment method to posted method
|
||||||
|
@ -445,7 +443,7 @@ class WC_Checkout {
|
||||||
foreach ( $this->checkout_fields as $fieldset_key => $fieldset ) {
|
foreach ( $this->checkout_fields as $fieldset_key => $fieldset ) {
|
||||||
|
|
||||||
// Skip shipping if not needed
|
// 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;
|
$skipped_shipping = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -513,7 +511,7 @@ class WC_Checkout {
|
||||||
break;
|
break;
|
||||||
case 'state' :
|
case 'state' :
|
||||||
// Get valid states
|
// 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 )
|
if ( $valid_states )
|
||||||
$valid_state_values = array_flip( array_map( 'strtolower', $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
|
// Update customer location to posted location so we can correctly check available shipping methods
|
||||||
if ( isset( $this->posted['billing_country'] ) )
|
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'] ) )
|
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'] ) )
|
if ( isset( $this->posted['billing_postcode'] ) )
|
||||||
$woocommerce->customer->set_postcode( $this->posted['billing_postcode'] );
|
WC()->customer->set_postcode( $this->posted['billing_postcode'] );
|
||||||
|
|
||||||
// Shipping Information
|
// Shipping Information
|
||||||
if ( ! $skipped_shipping ) {
|
if ( ! $skipped_shipping ) {
|
||||||
|
|
||||||
// Update customer location to posted location so we can correctly check available shipping methods
|
// Update customer location to posted location so we can correctly check available shipping methods
|
||||||
if ( isset( $this->posted['shipping_country'] ) )
|
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'] ) )
|
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'] ) )
|
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 {
|
} else {
|
||||||
|
|
||||||
// Update customer location to posted location so we can correctly check available shipping methods
|
// Update customer location to posted location so we can correctly check available shipping methods
|
||||||
if ( isset( $this->posted['billing_country'] ) )
|
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'] ) )
|
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'] ) )
|
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
|
// Update cart totals now we have customer address
|
||||||
$woocommerce->cart->calculate_totals();
|
WC()->cart->calculate_totals();
|
||||||
|
|
||||||
// Terms
|
// Terms
|
||||||
if ( ! isset( $_POST['woocommerce_checkout_update_totals'] ) && empty( $this->posted['terms'] ) && woocommerce_get_page_id( 'terms' ) > 0 )
|
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' ) );
|
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() ) ) )
|
if ( ! in_array( WC()->customer->get_shipping_country(), array_keys( WC()->countries->get_shipping_countries() ) ) )
|
||||||
wc_add_error( sprintf( __( 'Unfortunately <strong>we do not ship to %s</strong>. Please enter an alternative shipping address.', 'woocommerce' ), $woocommerce->countries->shipping_to_prefix() . ' ' . $woocommerce->customer->get_shipping_country() ) );
|
wc_add_error( sprintf( __( 'Unfortunately <strong>we do not ship to %s</strong>. Please enter an alternative shipping address.', 'woocommerce' ), WC()->countries->shipping_to_prefix() . ' ' . WC()->customer->get_shipping_country() ) );
|
||||||
|
|
||||||
// Validate Shipping Methods
|
// Validate Shipping Methods
|
||||||
$packages = WC()->shipping->get_packages();
|
$packages = WC()->shipping->get_packages();
|
||||||
|
@ -588,10 +586,10 @@ class WC_Checkout {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $woocommerce->cart->needs_payment() ) {
|
if ( WC()->cart->needs_payment() ) {
|
||||||
|
|
||||||
// Payment Method
|
// 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'] ] ) ) {
|
if ( ! isset( $available_gateways[ $this->posted['payment_method'] ] ) ) {
|
||||||
$this->payment_method = '';
|
$this->payment_method = '';
|
||||||
|
@ -648,10 +646,10 @@ class WC_Checkout {
|
||||||
do_action( 'woocommerce_checkout_order_processed', $order_id, $this->posted );
|
do_action( 'woocommerce_checkout_order_processed', $order_id, $this->posted );
|
||||||
|
|
||||||
// Process payment
|
// 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
|
// 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
|
// Process Payment
|
||||||
$result = $available_gateways[ $this->posted['payment_method'] ]->process_payment( $order_id );
|
$result = $available_gateways[ $this->posted['payment_method'] ]->process_payment( $order_id );
|
||||||
|
@ -680,7 +678,7 @@ class WC_Checkout {
|
||||||
$order->payment_complete();
|
$order->payment_complete();
|
||||||
|
|
||||||
// Empty the Cart
|
// Empty the Cart
|
||||||
$woocommerce->cart->empty_cart();
|
WC()->cart->empty_cart();
|
||||||
|
|
||||||
// Get redirect
|
// Get redirect
|
||||||
$return_url = $order->get_checkout_order_received_url();
|
$return_url = $order->get_checkout_order_received_url();
|
||||||
|
@ -723,12 +721,12 @@ class WC_Checkout {
|
||||||
array(
|
array(
|
||||||
'result' => 'failure',
|
'result' => 'failure',
|
||||||
'messages' => $messages,
|
'messages' => $messages,
|
||||||
'refresh' => isset( $woocommerce->session->refresh_totals ) ? 'true' : 'false',
|
'refresh' => isset( WC()->session->refresh_totals ) ? 'true' : 'false',
|
||||||
'reload' => isset( $woocommerce->session->reload_checkout ) ? 'true' : 'false'
|
'reload' => isset( WC()->session->reload_checkout ) ? 'true' : 'false'
|
||||||
)
|
)
|
||||||
) . '<!--WC_END-->';
|
) . '<!--WC_END-->';
|
||||||
|
|
||||||
unset( $woocommerce->session->refresh_totals, $woocommerce->session->reload_checkout );
|
unset( WC()->session->refresh_totals, WC()->session->reload_checkout );
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -742,8 +740,6 @@ class WC_Checkout {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get_value( $input ) {
|
public function get_value( $input ) {
|
||||||
global $woocommerce;
|
|
||||||
|
|
||||||
if ( ! empty( $_POST[ $input ] ) ) {
|
if ( ! empty( $_POST[ $input ] ) ) {
|
||||||
|
|
||||||
return woocommerce_clean( $_POST[ $input ] );
|
return woocommerce_clean( $_POST[ $input ] );
|
||||||
|
@ -768,17 +764,17 @@ class WC_Checkout {
|
||||||
|
|
||||||
switch ( $input ) {
|
switch ( $input ) {
|
||||||
case "billing_country" :
|
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" :
|
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" :
|
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" :
|
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" :
|
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" :
|
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 :
|
default :
|
||||||
return apply_filters( 'default_checkout_' . $input, '', $input );
|
return apply_filters( 'default_checkout_' . $input, '', $input );
|
||||||
}
|
}
|
||||||
|
|
|
@ -506,7 +506,7 @@ class WC_Form_Handler {
|
||||||
$variations[ $taxonomy ] = $value;
|
$variations[ $taxonomy ] = $value;
|
||||||
else {
|
else {
|
||||||
// For custom attributes, get the name from the slug
|
// 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 ) {
|
foreach ( $options as $option ) {
|
||||||
if ( sanitize_title( $option ) == $value ) {
|
if ( sanitize_title( $option ) == $value ) {
|
||||||
$value = $option;
|
$value = $option;
|
||||||
|
|
|
@ -22,19 +22,19 @@ class WC_Frontend_Scripts {
|
||||||
'woocommerce-layout' => array(
|
'woocommerce-layout' => array(
|
||||||
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-layout.css',
|
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-layout.css',
|
||||||
'deps' => '',
|
'deps' => '',
|
||||||
'version' => WOOCOMMERCE_VERSION,
|
'version' => WC_VERSION,
|
||||||
'media' => ''
|
'media' => ''
|
||||||
),
|
),
|
||||||
'woocommerce-smallscreen' => array(
|
'woocommerce-smallscreen' => array(
|
||||||
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-smallscreen.css',
|
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-smallscreen.css',
|
||||||
'deps' => 'woocommerce-layout',
|
'deps' => 'woocommerce-layout',
|
||||||
'version' => WOOCOMMERCE_VERSION,
|
'version' => WC_VERSION,
|
||||||
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
|
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
|
||||||
),
|
),
|
||||||
'woocommerce-general' => array(
|
'woocommerce-general' => array(
|
||||||
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce.css',
|
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce.css',
|
||||||
'deps' => '',
|
'deps' => '',
|
||||||
'version' => WOOCOMMERCE_VERSION,
|
'version' => WC_VERSION,
|
||||||
'media' => ''
|
'media' => ''
|
||||||
),
|
),
|
||||||
) );
|
) );
|
||||||
|
@ -58,35 +58,35 @@ class WC_Frontend_Scripts {
|
||||||
// Register any scripts for later use, or used as dependencies
|
// 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( '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-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( '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-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' ), WOOCOMMERCE_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' ), WOOCOMMERCE_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 );
|
wp_register_script( 'jquery-cookie', $assets_path . 'js/jquery-cookie/jquery.cookie' . $suffix . '.js', array( 'jquery' ), '1.3.1', true );
|
||||||
|
|
||||||
// Queue frontend scripts conditionally
|
// Queue frontend scripts conditionally
|
||||||
if ( $ajax_cart_en )
|
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() )
|
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 ( is_checkout() ) {
|
||||||
|
|
||||||
if ( get_option( 'woocommerce_enable_chosen' ) == 'yes' ) {
|
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_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' ) ) ) ) {
|
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', $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' );
|
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' );
|
wp_enqueue_script( 'wc-single-product' );
|
||||||
|
|
||||||
// Global frontend scripts
|
// 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( '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' ), WOOCOMMERCE_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
|
// Variables for JS scripts
|
||||||
wp_localize_script( 'woocommerce', 'woocommerce_params', apply_filters( 'woocommerce_params', array(
|
wp_localize_script( 'woocommerce', 'woocommerce_params', apply_filters( 'woocommerce_params', array(
|
||||||
|
|
|
@ -21,7 +21,7 @@ class WC_Install {
|
||||||
* Hook in tabs.
|
* Hook in tabs.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
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, 'install_actions' ) );
|
||||||
add_action( 'admin_init', array( $this, 'check_version' ), 5 );
|
add_action( 'admin_init', array( $this, 'check_version' ), 5 );
|
||||||
|
@ -165,7 +165,7 @@ class WC_Install {
|
||||||
update_option( 'woocommerce_db_version', '2.0.14' );
|
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' );
|
include( 'updates/woocommerce-update-2.1.php' );
|
||||||
update_option( 'woocommerce_db_version', '2.1.0' );
|
update_option( 'woocommerce_db_version', '2.1.0' );
|
||||||
}
|
}
|
||||||
|
@ -639,7 +639,7 @@ class WC_Install {
|
||||||
|
|
||||||
// Output Upgrade Notice
|
// Output Upgrade Notice
|
||||||
$matches = null;
|
$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 ) ) {
|
if ( preg_match( $regexp, $response['body'], $matches ) ) {
|
||||||
$notices = (array) preg_split('~[\r\n]+~', trim( $matches[1] ) );
|
$notices = (array) preg_split('~[\r\n]+~', trim( $matches[1] ) );
|
||||||
|
@ -655,7 +655,7 @@ class WC_Install {
|
||||||
|
|
||||||
// Output Changelog
|
// Output Changelog
|
||||||
$matches = null;
|
$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 ) ) {
|
if ( preg_match( $regexp, $response['body'], $matches ) ) {
|
||||||
$changelog = (array) preg_split('~[\r\n]+~', trim( $matches[2] ) );
|
$changelog = (array) preg_split('~[\r\n]+~', trim( $matches[2] ) );
|
||||||
|
|
|
@ -384,7 +384,7 @@ class WC_Order {
|
||||||
$tax_totals[ $code ]->is_compound = $tax[ 'compound' ];
|
$tax_totals[ $code ]->is_compound = $tax[ 'compound' ];
|
||||||
$tax_totals[ $code ]->label = isset( $tax[ 'label' ] ) ? $tax[ 'label' ] : $tax[ 'name' ];
|
$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 ]->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 );
|
return apply_filters( 'woocommerce_order_tax_totals', $tax_totals, $this );
|
||||||
|
@ -476,7 +476,7 @@ class WC_Order {
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function get_total_tax() {
|
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 ) {
|
public function get_item_tax( $item, $round = true ) {
|
||||||
$price = $item['line_tax'] / $item['qty'];
|
$price = $item['line_tax'] / $item['qty'];
|
||||||
$price = $round ? number_format( $price, 2, '.', '' ) : $price;
|
$price = $round ? woocommerce_round_tax_total( $price ) : $price;
|
||||||
return apply_filters( 'woocommerce_order_amount_item_tax', $price, $this );
|
return apply_filters( 'woocommerce_order_amount_item_tax', $price, $item, $round, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -594,7 +594,7 @@ class WC_Order {
|
||||||
* @return float
|
* @return float
|
||||||
*/
|
*/
|
||||||
public function get_line_tax( $item ) {
|
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -312,7 +312,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
foreach ( $post_terms as $term )
|
foreach ( $post_terms as $term )
|
||||||
$values[] = $term->slug;
|
$values[] = $term->slug;
|
||||||
} else {
|
} else {
|
||||||
$values = array_map( 'trim', explode( WOOCOMMERCE_DELIMITER, $attribute['value'] ) );
|
$values = array_map( 'trim', explode( WC_DELIMITER, $attribute['value'] ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
$values = array_unique( $values );
|
$values = array_unique( $values );
|
||||||
|
@ -320,7 +320,7 @@ class WC_Product_Variable extends WC_Product {
|
||||||
// Order custom attributes (non taxonomy) as defined
|
// Order custom attributes (non taxonomy) as defined
|
||||||
} elseif ( ! $attribute['is_taxonomy'] ) {
|
} 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;
|
$option_slugs = $values;
|
||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,9 @@ class WC_Tax {
|
||||||
/** @var array */
|
/** @var array */
|
||||||
public $matched_rates;
|
public $matched_rates;
|
||||||
|
|
||||||
|
|
||||||
|
var $log = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __construct function.
|
* __construct function.
|
||||||
*
|
*
|
||||||
|
@ -20,10 +23,182 @@ class WC_Tax {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
$this->precision = WC_ROUNDING_PRECISION;
|
||||||
$this->dp = (int) get_option( 'woocommerce_price_num_decimals' );
|
$this->dp = (int) get_option( 'woocommerce_price_num_decimals' );
|
||||||
$this->round_at_subtotal = get_option('woocommerce_tax_round_at_subtotal') == 'yes';
|
$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.
|
* 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);
|
return apply_filters('woocommerce_matched_rates', $matched_tax_rates, $tax_class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -361,172 +535,6 @@ class WC_Tax {
|
||||||
return array(); // return false
|
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.
|
* 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 ) {
|
public function get_tax_total( $taxes ) {
|
||||||
return array_sum( array_map( array( $this, 'round' ), $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 );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -41,7 +41,7 @@ class WC_Template_Loader {
|
||||||
|
|
||||||
$file = 'single-product.php';
|
$file = 'single-product.php';
|
||||||
$find[] = $file;
|
$find[] = $file;
|
||||||
$find[] = WOOCOMMERCE_TEMPLATE_PATH . $file;
|
$find[] = WC_TEMPLATE_PATH . $file;
|
||||||
|
|
||||||
} elseif ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
|
} elseif ( is_tax( 'product_cat' ) || is_tax( 'product_tag' ) ) {
|
||||||
|
|
||||||
|
@ -49,15 +49,15 @@ class WC_Template_Loader {
|
||||||
|
|
||||||
$file = 'taxonomy-' . $term->taxonomy . '.php';
|
$file = 'taxonomy-' . $term->taxonomy . '.php';
|
||||||
$find[] = 'taxonomy-' . $term->taxonomy . '-' . $term->slug . '.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[] = $file;
|
||||||
$find[] = WOOCOMMERCE_TEMPLATE_PATH . $file;
|
$find[] = WC_TEMPLATE_PATH . $file;
|
||||||
|
|
||||||
} elseif ( is_post_type_archive( 'product' ) || is_page( woocommerce_get_page_id( 'shop' ) ) ) {
|
} elseif ( is_post_type_archive( 'product' ) || is_page( woocommerce_get_page_id( 'shop' ) ) ) {
|
||||||
|
|
||||||
$file = 'archive-product.php';
|
$file = 'archive-product.php';
|
||||||
$find[] = $file;
|
$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' )
|
if ( get_post_type() !== 'product' )
|
||||||
return $template;
|
return $template;
|
||||||
|
|
||||||
if ( file_exists( STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_PATH . 'single-product-reviews.php' ))
|
if ( file_exists( STYLESHEETPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php' ))
|
||||||
return STYLESHEETPATH . '/' . WOOCOMMERCE_TEMPLATE_PATH . 'single-product-reviews.php';
|
return STYLESHEETPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php';
|
||||||
elseif ( file_exists( TEMPLATEPATH . '/' . WOOCOMMERCE_TEMPLATE_PATH . 'single-product-reviews.php' ))
|
elseif ( file_exists( TEMPLATEPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php' ))
|
||||||
return TEMPLATEPATH . '/' . WOOCOMMERCE_TEMPLATE_PATH . 'single-product-reviews.php';
|
return TEMPLATEPATH . '/' . WC_TEMPLATE_PATH . 'single-product-reviews.php';
|
||||||
elseif ( file_exists( STYLESHEETPATH . '/' . 'single-product-reviews.php' ))
|
elseif ( file_exists( STYLESHEETPATH . '/' . 'single-product-reviews.php' ))
|
||||||
return STYLESHEETPATH . '/' . 'single-product-reviews.php';
|
return STYLESHEETPATH . '/' . 'single-product-reviews.php';
|
||||||
elseif ( file_exists( TEMPLATEPATH . '/' . 'single-product-reviews.php' ))
|
elseif ( file_exists( TEMPLATEPATH . '/' . 'single-product-reviews.php' ))
|
||||||
|
|
|
@ -803,7 +803,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
||||||
'sslverify' => false,
|
'sslverify' => false,
|
||||||
'timeout' => 60,
|
'timeout' => 60,
|
||||||
'httpversion' => '1.1',
|
'httpversion' => '1.1',
|
||||||
'user-agent' => 'WooCommerce/' . WOOCOMMERCE_VERSION
|
'user-agent' => 'WooCommerce/' . WC_VERSION
|
||||||
);
|
);
|
||||||
|
|
||||||
// Post back to get a response
|
// Post back to get a response
|
||||||
|
|
|
@ -243,7 +243,7 @@ class WC_Shipping_Flat_Rate extends WC_Shipping_Method {
|
||||||
// Loop options
|
// Loop options
|
||||||
foreach ( $this->options as $option ) {
|
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;
|
if ( sizeof( $this_option ) !== 3 ) continue;
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,24 @@ function woocommerce_trim_zeros( $price ) {
|
||||||
return preg_replace( '/' . preg_quote( get_option( 'woocommerce_price_decimal_sep' ), '/' ) . '0++$/', '', $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.
|
* Format decimal numbers - format to a defined number of dp and remove trailing zeros.
|
||||||
*
|
*
|
||||||
|
|
|
@ -87,7 +87,7 @@ function wc_setup_product_data( $post ) {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function wc_generator_tag() {
|
function wc_generator_tag() {
|
||||||
echo "\n\n" . '<!-- WooCommerce Version -->' . "\n" . '<meta name="generator" content="WooCommerce ' . esc_attr( WOOCOMMERCE_VERSION ) . '" />' . "\n\n";
|
echo "\n\n" . '<!-- WooCommerce Version -->' . "\n" . '<meta name="generator" content="WooCommerce ' . esc_attr( WC_VERSION ) . '" />' . "\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1131,7 +1131,7 @@ function wc_cart_totals_order_total_html() {
|
||||||
foreach ( WC()->cart->get_tax_totals() as $code => $tax )
|
foreach ( WC()->cart->get_tax_totals() as $code => $tax )
|
||||||
$tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
|
$tax_string_array[] = sprintf( '%s %s', $tax->formatted_amount, $tax->label );
|
||||||
} else {
|
} 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 ) )
|
if ( ! empty( $tax_string_array ) )
|
||||||
|
|
|
@ -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 - Handling for password protected products.
|
||||||
* Feature - Schema markup selector for downloadables.
|
* Feature - Schema markup selector for downloadables.
|
||||||
* Feature - woocommerce_get_featured_product_ids function.
|
* 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 - 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).
|
* Feature - Coupon usage limits per user (using email + ID).
|
||||||
* Tweak - Added pagination to tax rate screens.
|
* Tweak - Added pagination to tax rate screens.
|
||||||
|
|
|
@ -59,7 +59,7 @@ if ( empty( $attributes ) && ( ! $product->enable_dimensions_display() || ( ! $p
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Convert pipes to commas and display values
|
// 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 );
|
echo apply_filters( 'woocommerce_attribute', wpautop( wptexturize( implode( ', ', $values ) ) ), $attribute, $values );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,7 +454,7 @@ function woocommerce_save_attributes() {
|
||||||
|
|
||||||
// Text based attributes - Posted values are term names - don't change to slugs
|
// Text based attributes - Posted values are term names - don't change to slugs
|
||||||
} else {
|
} 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
|
// Remove empty items in the array
|
||||||
|
@ -483,7 +483,7 @@ function woocommerce_save_attributes() {
|
||||||
} elseif ( isset( $attribute_values[ $i ] ) ) {
|
} elseif ( isset( $attribute_values[ $i ] ) ) {
|
||||||
|
|
||||||
// Text based, separate by pipe
|
// 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
|
// Custom attribute - Add attribute to array and set the values
|
||||||
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
|
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
|
||||||
|
@ -635,7 +635,7 @@ function woocommerce_link_all_variations() {
|
||||||
$options[] = $term->slug;
|
$options[] = $term->slug;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$options = explode( WOOCOMMERCE_DELIMITER, $attribute['value'] );
|
$options = explode( WC_DELIMITER, $attribute['value'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array_map( 'sanitize_title', array_map( 'trim', $options ) );
|
$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_subtotal_taxes = $tax->calc_tax( $line_subtotal, $tax_rates, false );
|
||||||
$line_taxes = $tax->calc_tax( $line_total, $tax_rates, false );
|
$line_taxes = $tax->calc_tax( $line_total, $tax_rates, false );
|
||||||
|
$line_subtotal_tax = array_sum( $line_subtotal_taxes );
|
||||||
$line_subtotal_tax = $tax->round( array_sum( $line_subtotal_taxes ) );
|
$line_tax = array_sum( $line_taxes );
|
||||||
$line_tax = $tax->round( array_sum( $line_taxes ) );
|
|
||||||
|
|
||||||
if ( $line_subtotal_tax < 0 )
|
if ( $line_subtotal_tax < 0 )
|
||||||
$line_subtotal_tax = 0;
|
$line_subtotal_tax = 0;
|
||||||
|
@ -1295,8 +1294,8 @@ function woocommerce_calc_line_taxes() {
|
||||||
$item['name'] = $tax_codes[ $key ];
|
$item['name'] = $tax_codes[ $key ];
|
||||||
$item['label'] = $tax->get_rate_label( $key );
|
$item['label'] = $tax->get_rate_label( $key );
|
||||||
$item['compound'] = $tax->is_compound( $key ) ? 1 : 0;
|
$item['compound'] = $tax->is_compound( $key ) ? 1 : 0;
|
||||||
$item['tax_amount'] = $tax->round( isset( $taxes[ $key ] ) ? $taxes[ $key ] : 0 );
|
$item['tax_amount'] = woocommerce_format_decimal( isset( $taxes[ $key ] ) ? $taxes[ $key ] : 0, false );
|
||||||
$item['shipping_tax_amount'] = $tax->round( isset( $shipping_taxes[ $key ] ) ? $shipping_taxes[ $key ] : 0 );
|
$item['shipping_tax_amount'] = woocommerce_format_decimal( isset( $shipping_taxes[ $key ] ) ? $shipping_taxes[ $key ] : 0, false );
|
||||||
|
|
||||||
if ( ! $item['label'] )
|
if ( ! $item['label'] )
|
||||||
$item['label'] = $woocommerce->countries->tax_or_vat();
|
$item['label'] = $woocommerce->countries->tax_or_vat();
|
||||||
|
|
|
@ -122,11 +122,7 @@ final class WooCommerce {
|
||||||
spl_autoload_register( array( $this, 'autoload' ) );
|
spl_autoload_register( array( $this, 'autoload' ) );
|
||||||
|
|
||||||
// Define constants
|
// Define constants
|
||||||
define( 'WOOCOMMERCE_PLUGIN_FILE', __FILE__ );
|
$this->define_constants();
|
||||||
define( 'WOOCOMMERCE_VERSION', $this->version );
|
|
||||||
define( 'WOOCOMMERCE_TEMPLATE_PATH', $this->template_path() );
|
|
||||||
if ( ! defined( 'WOOCOMMERCE_DELIMITER' ) )
|
|
||||||
define( 'WOOCOMMERCE_DELIMITER', '|' );
|
|
||||||
|
|
||||||
// Include required files
|
// Include required files
|
||||||
$this->includes();
|
$this->includes();
|
||||||
|
@ -157,8 +153,8 @@ final class WooCommerce {
|
||||||
return $this->$key();
|
return $this->$key();
|
||||||
else switch( $key ) {
|
else switch( $key ) {
|
||||||
case 'template_url':
|
case 'template_url':
|
||||||
_deprecated_argument( 'Woocommerce->template_url', '2.1', 'WOOCOMMERCE_TEMPLATE_PATH constant' );
|
_deprecated_argument( 'Woocommerce->template_url', '2.1', 'WC_TEMPLATE_PATH constant' );
|
||||||
return WOOCOMMERCE_TEMPLATE_PATH;
|
return WC_TEMPLATE_PATH;
|
||||||
case 'messages':
|
case 'messages':
|
||||||
_deprecated_argument( 'Woocommerce->messages', '2.1', 'The "messages" field is moved to the messages helper class.' );
|
_deprecated_argument( 'Woocommerce->messages', '2.1', 'The "messages" field is moved to the messages helper class.' );
|
||||||
return $this->session->get( 'wc_messages', array() );
|
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.
|
* 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/wc-core-functions.php' );
|
||||||
include( 'includes/class-wc-install.php' );
|
include( 'includes/class-wc-install.php' );
|
||||||
include( 'includes/class-wc-download-handler.php' );
|
include( 'includes/class-wc-download-handler.php' );
|
||||||
|
@ -483,7 +501,7 @@ final class WooCommerce {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function template_path() {
|
public function template_path() {
|
||||||
return apply_filters( 'woocommerce_template_path', 'woocommerce/' );
|
return apply_filters( 'WC_TEMPLATE_PATH', 'woocommerce/' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue