WooCommerce Germanized - Version 1.9.4

Version Description

  • Fix: Fee tax share calculation for WC 3.2
  • Fix: Gateway fee saving
Download this release

Release Info

Developer vendidero
Plugin Icon 128x128 WooCommerce Germanized
Version 1.9.4
Comparing to
See all releases

Code changes from version 1.9.3 to 1.9.4

includes/class-wc-gzd-checkout.php CHANGED
@@ -65,7 +65,9 @@ class WC_GZD_Checkout {
65
  add_action( 'woocommerce_review_order_before_shipping', array( $this, 'remove_shipping_rates' ), 0 );
66
 
67
  // Add better fee taxation
68
- add_action( 'woocommerce_cart_calculate_fees', array( $this, 'do_fee_tax_calculation' ), PHP_INT_MAX, 1 );
 
 
69
 
70
  // Disallow user order cancellation
71
  if ( get_option( 'woocommerce_gzd_checkout_stop_order_cancellation' ) == 'yes' ) {
@@ -342,22 +344,99 @@ class WC_GZD_Checkout {
342
  *
343
  * @param WC_Cart $cart
344
  */
345
- public function do_fee_tax_calculation( WC_Cart $cart ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  if ( get_option( 'woocommerce_gzd_fee_tax' ) != 'yes' )
347
  return;
 
 
 
 
348
  if ( ! empty( $cart->fees ) ) {
349
  $tax_shares = wc_gzd_get_cart_tax_share( 'fee' );
350
  foreach ( $cart->fees as $key => $fee ) {
 
351
  if ( ! $fee->taxable && get_option( 'woocommerce_gzd_fee_tax_force' ) != 'yes' )
352
- continue;
 
353
  // Calculate gross price if necessary
354
  if ( $fee->taxable ) {
355
  $fee_tax_rates = WC_Tax::get_rates( $fee->tax_class );
356
  $fee_tax = WC_Tax::calc_tax( $fee->amount, $fee_tax_rates, false );
357
  $fee->amount += array_sum( $fee_tax );
358
  }
 
359
  // Set fee to nontaxable to avoid WooCommerce default tax calculation
360
  $fee->taxable = false;
 
361
  // Calculate tax class share
362
  if ( ! empty( $tax_shares ) ) {
363
  $fee_taxes = array();
65
  add_action( 'woocommerce_review_order_before_shipping', array( $this, 'remove_shipping_rates' ), 0 );
66
 
67
  // Add better fee taxation
68
+ add_action( 'woocommerce_calculate_totals', array( $this, 'do_fee_tax_calculation' ), PHP_INT_MAX, 1 );
69
+ // Pre WC 3.2
70
+ add_action( 'woocommerce_cart_calculate_fees', array( $this, 'do_fee_tax_calculation_legacy' ), PHP_INT_MAX, 1 );
71
 
72
  // Disallow user order cancellation
73
  if ( get_option( 'woocommerce_gzd_checkout_stop_order_cancellation' ) == 'yes' ) {
344
  *
345
  * @param WC_Cart $cart
346
  */
347
+ public function do_fee_tax_calculation( $cart ) {
348
+
349
+ if ( get_option( 'woocommerce_gzd_fee_tax' ) != 'yes' )
350
+ return;
351
+
352
+ if ( ! method_exists( $cart, 'set_fee_taxes' ) )
353
+ return;
354
+
355
+ if ( ! empty( $cart->get_fees() ) ) {
356
+
357
+ $tax_shares = wc_gzd_get_cart_tax_share( 'fee' );
358
+ $fee_tax_total = 0;
359
+ $fee_tax_data = array();
360
+ $new_fees = array();
361
+
362
+ foreach ( $cart->get_fees() as $key => $fee ) {
363
+
364
+ if ( ! $fee->taxable && get_option( 'woocommerce_gzd_fee_tax_force' ) !== 'yes' )
365
+ continue;
366
+
367
+ // Calculate gross price if necessary
368
+ if ( $fee->taxable ) {
369
+ $fee_tax_rates = WC_Tax::get_rates( $fee->tax_class );
370
+ $fee_tax = WC_Tax::calc_tax( $fee->amount, $fee_tax_rates, false );
371
+ $fee->amount += array_sum( $fee_tax );
372
+ }
373
+
374
+ // Set fee to nontaxable to avoid WooCommerce default tax calculation
375
+ $fee->taxable = false;
376
+
377
+ // Calculate tax class share
378
+ if ( ! empty( $tax_shares ) ) {
379
+ $fee_taxes = array();
380
+
381
+ foreach ( $tax_shares as $rate => $class ) {
382
+ $tax_rates = WC_Tax::get_rates( $rate );
383
+ $tax_shares[ $rate ][ 'fee_tax_share' ] = $fee->amount * $class[ 'share' ];
384
+ $tax_shares[ $rate ][ 'fee_tax' ] = WC_Tax::calc_tax( ( $fee->amount * $class[ 'share' ] ), $tax_rates, true );
385
+ $fee_taxes += $tax_shares[ $rate ][ 'fee_tax' ];
386
+ }
387
+
388
+ foreach ( $tax_shares as $rate => $class ) {
389
+
390
+ foreach ( $class['fee_tax'] as $rate_id => $tax ) {
391
+ if ( ! array_key_exists( $rate_id, $fee_tax_data ) ) {
392
+ $fee_tax_data[ $rate_id ] = 0;
393
+ }
394
+ $fee_tax_data[ $rate_id ] += $tax;
395
+ }
396
+
397
+ $fee_tax_total += array_sum( $class['fee_tax'] );
398
+ }
399
+
400
+ $fee->tax_data = $fee_taxes;
401
+ $fee->tax = $fee_tax_total;
402
+ $fee->amount = $fee->amount - $fee->tax;
403
+ $fee->total = $fee->amount;
404
+
405
+ $new_fees[ $key ] = $fee;
406
+ }
407
+ }
408
+
409
+ $cart->fees_api()->set_fees( $new_fees );
410
+ $cart->set_fee_tax( array_sum( $fee_tax_data ) );
411
+ $cart->set_fee_taxes( $fee_tax_data );
412
+ }
413
+ }
414
+
415
+ public function do_fee_tax_calculation_legacy( $cart ) {
416
+
417
  if ( get_option( 'woocommerce_gzd_fee_tax' ) != 'yes' )
418
  return;
419
+
420
+ if ( method_exists( $cart, 'set_fee_taxes' ) )
421
+ return;
422
+
423
  if ( ! empty( $cart->fees ) ) {
424
  $tax_shares = wc_gzd_get_cart_tax_share( 'fee' );
425
  foreach ( $cart->fees as $key => $fee ) {
426
+
427
  if ( ! $fee->taxable && get_option( 'woocommerce_gzd_fee_tax_force' ) != 'yes' )
428
+ continue;
429
+
430
  // Calculate gross price if necessary
431
  if ( $fee->taxable ) {
432
  $fee_tax_rates = WC_Tax::get_rates( $fee->tax_class );
433
  $fee_tax = WC_Tax::calc_tax( $fee->amount, $fee_tax_rates, false );
434
  $fee->amount += array_sum( $fee_tax );
435
  }
436
+
437
  // Set fee to nontaxable to avoid WooCommerce default tax calculation
438
  $fee->taxable = false;
439
+
440
  // Calculate tax class share
441
  if ( ! empty( $tax_shares ) ) {
442
  $fee_taxes = array();
includes/class-wc-gzd-payment-gateways.php CHANGED
@@ -21,11 +21,18 @@ class WC_GZD_Payment_Gateways {
21
  }
22
 
23
  public function __construct() {
 
 
 
24
  add_action( 'woocommerce_settings_checkout', array( $this, 'init_fields' ), 0 );
25
  add_action( 'woocommerce_calculate_totals', array( $this, 'checkout' ) );
26
  add_action( 'woocommerce_cart_calculate_fees', array( $this, 'init_fee' ), 0 );
27
  }
28
 
 
 
 
 
29
  /**
30
  * Set default order button text instead of the button text defined by each payment gateway.
31
  * Can be overriden by setting force_order_button_text within payment gateway class
21
  }
22
 
23
  public function __construct() {
24
+ // Make sure fields are inited before being saved
25
+ add_action( 'woocommerce_settings_save_checkout', array( $this, 'save_fields' ), 5 );
26
+ // Init gateway fields
27
  add_action( 'woocommerce_settings_checkout', array( $this, 'init_fields' ), 0 );
28
  add_action( 'woocommerce_calculate_totals', array( $this, 'checkout' ) );
29
  add_action( 'woocommerce_cart_calculate_fees', array( $this, 'init_fee' ), 0 );
30
  }
31
 
32
+ public function save_fields() {
33
+ $this->init_fields();
34
+ }
35
+
36
  /**
37
  * Set default order button text instead of the button text defined by each payment gateway.
38
  * Can be overriden by setting force_order_button_text within payment gateway class
includes/compatibility/class-wc-gzd-compatibility-woocommerce-subscriptions.php CHANGED
@@ -147,7 +147,7 @@ class WC_GZD_Compatibility_Woocommerce_Subscriptions extends WC_GZD_Compatibilit
147
  }
148
  }
149
  } else {
150
- $base_rate = array_values( WC_Tax::get_shop_base_rate() );
151
  $base_rate = (object) $base_rate[0];
152
  $base_rate->rate = $base_rate->rate;
153
  $tax_array[] = array( 'tax' => $base_rate, 'contains' => array( $base_rate ), 'amount' => $cart->get_taxes_total( true, true ) );
147
  }
148
  }
149
  } else {
150
+ $base_rate = array_values( WC_Tax::get_base_tax_rates() );
151
  $base_rate = (object) $base_rate[0];
152
  $base_rate->rate = $base_rate->rate;
153
  $tax_array[] = array( 'tax' => $base_rate, 'contains' => array( $base_rate ), 'amount' => $cart->get_taxes_total( true, true ) );
readme.txt CHANGED
@@ -5,7 +5,7 @@ Requires at least: 3.8
5
  Tested up to: 4.8
6
  WC requires at least: 2.4
7
  WC tested up to: 3.2
8
- Stable tag: 1.9.3
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
@@ -169,6 +169,10 @@ Bug reports may be filed via our [GitHub repository](https://github.com/vendider
169
 
170
  == Changelog ==
171
 
 
 
 
 
172
  = 1.9.3 =
173
  * Fix: PHP Warning regarding WC_GZD_Shipping_Rate
174
  * Fix: Free shipping auto select WC 3.2
5
  Tested up to: 4.8
6
  WC requires at least: 2.4
7
  WC tested up to: 3.2
8
+ Stable tag: 1.9.4
9
  License: GPLv3
10
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
11
 
169
 
170
  == Changelog ==
171
 
172
+ = 1.9.4 =
173
+ * Fix: Fee tax share calculation for WC 3.2
174
+ * Fix: Gateway fee saving
175
+
176
  = 1.9.3 =
177
  * Fix: PHP Warning regarding WC_GZD_Shipping_Rate
178
  * Fix: Free shipping auto select WC 3.2
woocommerce-germanized.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: WooCommerce Germanized
4
  * Plugin URI: https://www.vendidero.de/woocommerce-germanized
5
  * Description: Extends WooCommerce to become a legally compliant store for the german market.
6
- * Version: 1.9.3
7
  * Author: Vendidero
8
  * Author URI: https://vendidero.de
9
  * Requires at least: 3.8
@@ -31,7 +31,7 @@ final class WooCommerce_Germanized {
31
  *
32
  * @var string
33
  */
34
- public $version = '1.9.3';
35
 
36
  /**
37
  * Single instance of WooCommerce Germanized Main Class
3
  * Plugin Name: WooCommerce Germanized
4
  * Plugin URI: https://www.vendidero.de/woocommerce-germanized
5
  * Description: Extends WooCommerce to become a legally compliant store for the german market.
6
+ * Version: 1.9.4
7
  * Author: Vendidero
8
  * Author URI: https://vendidero.de
9
  * Requires at least: 3.8
31
  *
32
  * @var string
33
  */
34
+ public $version = '1.9.4';
35
 
36
  /**
37
  * Single instance of WooCommerce Germanized Main Class