diff --git a/one-stop-shop-woocommerce.php b/one-stop-shop-woocommerce.php index 4a58616..b3c5cac 100644 --- a/one-stop-shop-woocommerce.php +++ b/one-stop-shop-woocommerce.php @@ -5,7 +5,7 @@ * Description: Comply with the One Stop Shop procedure while using WooCommerce. * Author: vendidero * Author URI: https://vendidero.de - * Version: 1.6.0 + * Version: 1.6.1 * Requires PHP: 5.6 * License: GPLv3 * Tested up to: 6.4 diff --git a/package.json b/package.json index c7d29a9..0000970 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "one-stop-shop-woocommerce", "title": "One Stop Shop for WooCommerce", - "version": "1.6.0", + "version": "1.6.1", "homepage": "https://vendidero.de", "repository": { "type": "git", diff --git a/readme.txt b/readme.txt index a66a62a..9e57cbe 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Requires at least: 5.4 Tested up to: 6.4 WC requires at least: 3.9 WC tested up to: 8.5 -Stable tag: 1.6.0 +Stable tag: 1.6.1 Requires PHP: 5.6 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -61,6 +61,9 @@ Bug reports may be filed via our [GitHub repository](https://github.com/vendider 3. Create a new report == Changelog == += 1.6.1 = +* Fix: Apply base taxes for EU-wide b2b orders (without UID/vat exempt) only + = 1.6.0 = * Improvement: Exclude b2b orders (without and with UID, e.g. non-taxes) from OSS * Improvement: Calculate base location taxes for b2b checkouts diff --git a/src/Package.php b/src/Package.php index 96f4933..74fb3e3 100644 --- a/src/Package.php +++ b/src/Package.php @@ -16,7 +16,7 @@ class Package { * * @var string */ - const VERSION = '1.6.0'; + const VERSION = '1.6.1'; /** * Init the package diff --git a/src/Tax.php b/src/Tax.php index 7205d2c..827f62b 100644 --- a/src/Tax.php +++ b/src/Tax.php @@ -21,8 +21,8 @@ public static function init() { add_action( 'woocommerce_before_save_order_item', array( __CLASS__, 'maybe_filter_order_item_tax_class' ) ); add_filter( 'woocommerce_adjust_non_base_location_prices', array( __CLASS__, 'disable_location_price' ), 250 ); - add_filter( 'woocommerce_customer_taxable_address', array( __CLASS__, 'b2b_taxable_customer_location' ), 10 ); - add_filter( 'woocommerce_order_get_tax_location', array( __CLASS__, 'b2b_taxable_order_location' ), 10, 2 ); + add_filter( 'woocommerce_customer_taxable_address', array( __CLASS__, 'b2b_eu_taxable_customer_location' ), 10 ); + add_filter( 'woocommerce_order_get_tax_location', array( __CLASS__, 'b2b_eu_taxable_order_location' ), 10, 2 ); add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'invalidate_shipping_session' ), 100 ); } @@ -101,17 +101,19 @@ public static function invalidate_shipping_session( $cart ) { * * @return array|mixed */ - public static function b2b_taxable_customer_location( $location ) { - if ( - ( Helper::current_request_has_vat_exempt() && apply_filters( 'oss_woocommerce_force_base_tax_rate_for_vat_exempt_net_calculation', true ) ) || - ( Helper::current_request_is_b2b() && apply_filters( 'oss_woocommerce_force_base_tax_rate_for_b2b', true ) ) - ) { - $location = array( - WC()->countries->get_base_country(), - WC()->countries->get_base_state(), - WC()->countries->get_base_postcode(), - WC()->countries->get_base_city(), - ); + public static function b2b_eu_taxable_customer_location( $location ) { + if ( Helper::is_eu_vat_country( $location[0], $location[2] ) ) { + if ( + ( Helper::current_request_has_vat_exempt() && apply_filters( 'oss_woocommerce_force_base_tax_rate_for_vat_exempt_net_calculation', true ) ) || + ( Helper::current_request_is_b2b() && apply_filters( 'oss_woocommerce_force_base_tax_rate_for_b2b', true ) ) + ) { + $location = array( + WC()->countries->get_base_country(), + WC()->countries->get_base_state(), + WC()->countries->get_base_postcode(), + WC()->countries->get_base_city(), + ); + } } return $location; @@ -148,24 +150,34 @@ public static function order_has_taxable_company( $order ) { * * @return array */ - public static function b2b_taxable_order_location( $args, $order ) { - $has_vat_exempt = apply_filters( 'woocommerce_order_is_vat_exempt', 'yes' === $order->get_meta( 'is_vat_exempt' ), $order ); + public static function b2b_eu_taxable_order_location( $args, $order ) { + $args = wp_parse_args( + $args, + array( + 'country' => '', + 'postcode' => '', + ) + ); - if ( isset( $args['company'] ) ) { - $has_company = apply_filters( 'oss_woocommerce_order_has_taxable_company', ! empty( $args['company'] ), $order ); - } else { - $has_company = self::order_has_taxable_company( $order ); - } + if ( Helper::is_eu_vat_country( $args['country'], $args['postcode'] ) ) { + $has_vat_exempt = apply_filters( 'woocommerce_order_is_vat_exempt', 'yes' === $order->get_meta( 'is_vat_exempt' ), $order ); - if ( - ( $has_vat_exempt && apply_filters( 'oss_woocommerce_force_base_tax_rate_for_vat_exempt_net_calculation', true ) ) || - ( $has_company && apply_filters( 'oss_woocommerce_force_base_tax_rate_for_b2b', true ) ) - ) { - $args['country'] = Helper::get_base_country(); + if ( isset( $args['company'] ) ) { + $has_company = apply_filters( 'oss_woocommerce_order_has_taxable_company', ! empty( $args['company'] ), $order ); + } else { + $has_company = self::order_has_taxable_company( $order ); + } + + if ( + ( $has_vat_exempt && apply_filters( 'oss_woocommerce_force_base_tax_rate_for_vat_exempt_net_calculation', true ) ) || + ( $has_company && apply_filters( 'oss_woocommerce_force_base_tax_rate_for_b2b', true ) ) + ) { + $args['country'] = Helper::get_base_country(); - $args['state'] = WC()->countries->get_base_state(); - $args['postcode'] = WC()->countries->get_base_postcode(); - $args['city'] = WC()->countries->get_base_city(); + $args['state'] = WC()->countries->get_base_state(); + $args['postcode'] = WC()->countries->get_base_postcode(); + $args['city'] = WC()->countries->get_base_city(); + } } return $args;