Skip to content

Commit

Permalink
Apply base taxes for EU-wide b2b orders (without UID/vat exempt) onl…
Browse files Browse the repository at this point in the history
…y. Version bump to 1.6.1.
  • Loading branch information
dennisnissle committed Feb 9, 2024
1 parent 534fc47 commit 0af5021
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
2 changes: 1 addition & 1 deletion one-stop-shop-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Package {
*
* @var string
*/
const VERSION = '1.6.0';
const VERSION = '1.6.1';

/**
* Init the package
Expand Down
68 changes: 40 additions & 28 deletions src/Tax.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0af5021

Please sign in to comment.