Skip to content

Commit

Permalink
Use main service calculation mode by default. Test fixes. Apply fee s…
Browse files Browse the repository at this point in the history
…kip forced additional costs taxation filter during order calculation too.
  • Loading branch information
dennisnissle committed Jan 26, 2024
1 parent b694315 commit fb617c7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function get_additional_costs_settings() {
'desc_tip' => true,
'id' => 'woocommerce_gzd_tax_mode_additional_costs',
'type' => 'radio',
'default' => 'split_tax',
'default' => 'main_service',
'options' => array(
'none' => __( 'WooCommerce default', 'woocommerce-germanized' ),
'split_tax' => __( 'Proportionate', 'woocommerce-germanized' ),
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-gzd-coupon-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ public function fee_is_voucher( $fee ) {
} else {
$fee_id = isset( $fee->object ) ? $fee->object->id : $fee->id;

return strstr( $fee_id, 'voucher_' );
return strstr( str_replace( '-', '_', $fee_id ), 'voucher_' );
}
}

Expand Down
22 changes: 22 additions & 0 deletions includes/class-wc-gzd-order-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,28 @@ public function adjust_additional_costs_item_taxes( $item, $calculate_tax_for =
return;
}

if ( is_a( $item, 'WC_Order_Item_Fee' ) ) {
$fee_props = (object) array(
'id' => '',
'name' => '',
'tax_class' => '',
'taxable' => false,
'amount' => 0,
'total' => 0,
);

$fee_props->name = $item->get_name();
$fee_props->tax_class = $item->get_tax_class();
$fee_props->taxable = 'taxable' === $item->get_tax_status();
$fee_props->amount = $item->get_amount();
$fee_props->id = sanitize_title( $fee_props->name );
$fee_props->object = $fee_props;

if ( ! apply_filters( 'woocommerce_gzd_force_fee_tax_calculation', true, $fee_props ) ) {
return;
}
}

if ( $order = $item->get_order() ) {
$item->delete_meta_data( '_split_taxes' );
$item->delete_meta_data( '_tax_shares' );
Expand Down
2 changes: 1 addition & 1 deletion includes/wc-gzd-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ function wc_gzd_format_unit_price( $price, $unit, $unit_base, $product_units = '
}

function wc_gzd_get_additional_costs_tax_calculation_mode() {
$value = get_option( 'woocommerce_gzd_tax_mode_additional_costs', 'split_tax' );
$value = get_option( 'woocommerce_gzd_tax_mode_additional_costs', 'main_service' );

if ( ! in_array( $value, array( 'none', 'split_tax', 'main_service' ), true ) ) {
$value = 'none';
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/helpers/class-wc-gzd-helper-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static function create_billing_order( $incl_tax = true, $items = array(),
$item->set_props(
array(
'method_title' => 'shipping',
'total' => 8.403361,
'total' => 10.0, // Germanized, by default, treats those as gross
)
);
} else {
Expand Down

0 comments on commit fb617c7

Please sign in to comment.