WC_Tax::calc_exclusive_tax()
Calc tax from exclusive price.
Метод класса: WC_Tax{}
Хуки из метода
Возвращает
Массив
.
Использование
$result = WC_Tax::calc_exclusive_tax( $price, $rates );
- $price(float) (обязательный)
- Price to calculate tax for.
- $rates(массив) (обязательный)
- Array of tax rates.
Код WC_Tax::calc_exclusive_tax() WC Tax::calc exclusive tax WC 9.5.1
public static function calc_exclusive_tax( $price, $rates ) { $taxes = array(); $price = (float) $price; if ( ! empty( $rates ) ) { foreach ( $rates as $key => $rate ) { if ( 'yes' === $rate['compound'] ) { continue; } $tax_amount = $price * ( floatval( $rate['rate'] ) / 100 ); $tax_amount = apply_filters( 'woocommerce_price_ex_tax_amount', $tax_amount, $key, $rate, $price ); // ADVANCED: Allow third parties to modify this rate. if ( ! isset( $taxes[ $key ] ) ) { $taxes[ $key ] = (float) $tax_amount; } else { $taxes[ $key ] += (float) $tax_amount; } } $pre_compound_total = array_sum( $taxes ); // Compound taxes. foreach ( $rates as $key => $rate ) { if ( 'no' === $rate['compound'] ) { continue; } $the_price_inc_tax = $price + $pre_compound_total; $tax_amount = $the_price_inc_tax * ( floatval( $rate['rate'] ) / 100 ); $tax_amount = apply_filters( 'woocommerce_price_ex_tax_amount', $tax_amount, $key, $rate, $price, $the_price_inc_tax, $pre_compound_total ); // ADVANCED: Allow third parties to modify this rate. if ( ! isset( $taxes[ $key ] ) ) { $taxes[ $key ] = (float) $tax_amount; } else { $taxes[ $key ] += (float) $tax_amount; } $pre_compound_total = array_sum( $taxes ); } } /** * Round all taxes to precision (4DP) before passing them back. Note, this is not the same rounding * as in the cart calculation class which, depending on settings, will round to 2DP when calculating * final totals. Also unlike that class, this rounds .5 up for all cases. */ $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); return $taxes; }