Home Forums Basel support forum Price Filter Ranges Reply To: Price Filter Ranges

#1126

javilap
Participant

Hello, You are right!

I just wanna ask for your help to do something. I need to change the way taxes are calculated. I changed for a while the code on woocommerce, but I need to revert this because I know it is not the way to do that.

I need to add a function on my functions.php just like I added the free shipping hide, or you added the filter range… The problem is, that I don’t know how to add a function for this code:

/**
* Calc tax from inclusive price.
*
* @param float $price
* @param array $rates
* @return array
*/
public static function calc_inclusive_tax( $price, $rates ) {
$taxes = array();

if ( $rates ) {
// Multiple taxes
foreach ( $rates as $key => $rate ) {

if ( $rate[‘compound’] == ‘yes’ )
continue;

$tax_amount = $price * ( $rate[‘rate’] / 100 );

// ADVANCED: Allow third parties to modify this rate
$tax_amount = apply_filters( ‘woocommerce_price_in_tax_amount’, $tax_amount, $key, $rate, $price );

// Add rate
if ( ! isset( $taxes[ $key ] ) )
$taxes[ $key ] = $tax_amount;
else
$taxes[ $key ] += $tax_amount;
}

$pre_compound_total = array_sum( $taxes );

// Compound taxes
foreach ( $rates as $key => $rate ) {

if ( $rate[‘compound’] == ‘no’ )
continue;

$the_price_inc_tax = $price + ( $pre_compound_total );

$tax_amount = $the_price_inc_tax * ( $rate[‘rate’] / 100 );

// ADVANCED: Allow third parties to modify this rate
$tax_amount = apply_filters( ‘woocommerce_price_i_tax_amount’, $tax_amount, $key, $rate, $price, $the_price_inc_tax, $pre_compound_total );

// Add rate
if ( ! isset( $taxes[ $key ] ) )
$taxes[ $key ] = $tax_amount;
else
$taxes[ $key ] += $tax_amount;
}
}

return $taxes;
}

Can you help me please telling me how can add this function to my child theme? Thank you!!!!