diff --git a/README.md b/README.md index bcbbd74..b114207 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Unreleased updates ------------------ * Fix - WPML exchange rates (apply filter `wcml_raw_price_amount`) +* Fix - tax class when taxes by cart items is on - applies the highest used tax. Thanks to [morvy](https://github.com/morvy) ## Credits diff --git a/inc/class-pay4pay.php b/inc/class-pay4pay.php index 903c30d..dfb8324 100644 --- a/inc/class-pay4pay.php +++ b/inc/class-pay4pay.php @@ -216,6 +216,25 @@ public function calculate_pay4payment() { // WooCommerce Fee is always ex taxes. We need to subtract taxes, WC will add them again later. if ( $taxable && $include_taxes ) { + // Apply the highest tax in the cart (see #65) + if ( $tax_class === 'inherit' ) { + $highestTaxRate = 0; + if ( $cart->get_cart() ) { + foreach ( $cart->get_cart() as $item ) { + if ( !$item['line_tax'] || !$item['line_total'] ) { + $itemTaxRate = 0; + } else { + $itemTaxRate = $item['line_tax'] / $item['line_total']; + } + + if ( $itemTaxRate >= $highestTaxRate ) { + $highestTaxRate = $itemTaxRate; + $tax_class = $item['data']->tax_class; + } + } + } + } + $tax_rates = WC_Tax::get_rates( $tax_class ); $factor = 1;