Fixes to tax system to work with VAT exemption
This commit is contained in:
parent
05a1046968
commit
ba9b035c65
|
@ -345,24 +345,14 @@ class woocommerce_cart {
|
|||
|
||||
$rate = $_tax->get_rate( $_product->get_tax_class() );
|
||||
|
||||
if (get_option('woocommerce_prices_include_tax')=='yes') :
|
||||
|
||||
$tax_amount = $_tax->calc_tax( $_product->get_price(), $rate, true ) * $values['quantity'];
|
||||
|
||||
else :
|
||||
|
||||
$tax_amount = $_tax->calc_tax( $_product->get_price(), $rate, false ) * $values['quantity'];
|
||||
|
||||
endif;
|
||||
$tax_amount = $_tax->calc_tax( $_product->get_price(), $rate, true ) * $values['quantity'];
|
||||
|
||||
/**
|
||||
* Checkout calculations when customer is OUTSIDE the shop base country and price INCLUDE tax
|
||||
*/
|
||||
if (get_option('woocommerce_prices_include_tax')=='yes' && $woocommerce->customer->is_customer_outside_base() && defined('WOOCOMMERCE_CHECKOUT') && WOOCOMMERCE_CHECKOUT ) :
|
||||
|
||||
/**
|
||||
* Our prices include tax so we need to take the base tax rate into consideration of our shop's country
|
||||
*
|
||||
* Lets get the base rate first
|
||||
*/
|
||||
$base_rate = $_tax->get_shop_base_rate( $_product->get_tax_class() );
|
||||
// Get the base rate first
|
||||
$base_rate = $_tax->get_shop_base_rate( $_product->tax_class );
|
||||
|
||||
// Calc tax for base country
|
||||
$base_tax_amount = $_tax->calc_tax( $_product->get_price(), $base_rate, true);
|
||||
|
@ -374,6 +364,20 @@ class woocommerce_cart {
|
|||
// Finally, update $total_item_price to reflect tax amounts
|
||||
$total_item_price = ($total_item_price - ($base_tax_amount * $values['quantity']) + $tax_amount);
|
||||
|
||||
/**
|
||||
* Checkout calculations when customer is INSIDE the shop base country and price INCLUDE tax
|
||||
*/
|
||||
elseif (get_option('woocommerce_prices_include_tax')=='yes' && $_product->get_tax_class() !== $_product->tax_class) :
|
||||
|
||||
// Calc tax for original rate
|
||||
$original_tax_amount = $_tax->calc_tax( $_product->get_price(), $_tax->get_rate( $_product->tax_class ), true);
|
||||
|
||||
// Now calc tax for new rate (which now excludes tax)
|
||||
$tax_amount = $_tax->calc_tax( ( $_product->get_price() - $original_tax_amount ), $rate, false );
|
||||
$tax_amount = $tax_amount * $values['quantity'];
|
||||
|
||||
$total_item_price = ($total_item_price - ($original_tax_amount * $values['quantity']) + $tax_amount);
|
||||
|
||||
endif;
|
||||
|
||||
endif;
|
||||
|
|
|
@ -429,7 +429,7 @@ class woocommerce_product {
|
|||
return $this->price;
|
||||
}
|
||||
|
||||
/** Returns the price (excluding tax) */
|
||||
/** Returns the price (excluding tax) - ignores tax_class filters since the price may *include* tax and thus needs subtracting */
|
||||
function get_price_excluding_tax() {
|
||||
|
||||
$price = $this->price;
|
||||
|
@ -472,7 +472,7 @@ class woocommerce_product {
|
|||
if ( $this->is_taxable() && get_option('woocommerce_calc_taxes')=='yes') :
|
||||
|
||||
$_tax = &new woocommerce_tax();
|
||||
$rate = $_tax->get_shop_base_rate( $this->get_tax_class() );
|
||||
$rate = $_tax->get_shop_base_rate( $this->tax_class ); // Get tax class directly - ignore filters
|
||||
|
||||
return $rate;
|
||||
|
||||
|
|
|
@ -110,6 +110,8 @@ class woocommerce_tax {
|
|||
function get_rate( $tax_class = '' ) {
|
||||
global $woocommerce;
|
||||
|
||||
$tax_class = sanitize_title($tax_class);
|
||||
|
||||
/* Checkout uses customer location, otherwise use store base rate */
|
||||
if ( defined('WOOCOMMERCE_CHECKOUT') && WOOCOMMERCE_CHECKOUT ) :
|
||||
|
||||
|
|
Loading…
Reference in New Issue