Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tax exclusive if coupon applied else tax inclusive in items

I have setup taxes inclusive for all my items and filled MRP in price. But now I want to apply tax inclusive if customer didn't applied coupon i.e. buying on MRP. But when customer applies coupon I need to apply taxes on after discount amount.

Is it possible with settings within Woocommerce or is there any plugin available?

For e.g.
**Case I**
Product MRP = 670
Shipping    =  50
Tax 18%     = 102
Final price = 670 (Including Taxes) 
It's Fine.


**Case II**
Product MRP = 670
Discount 40%= 268
Price       = 402
Shipping    =  50
Tax 18%     =  61
Final price = 452 (Including Taxes)
But I need tax to calculated exclusively on discounted price i.e. 402+18% = 474+50 (Ship) = 524

I have tried following filter in my custom plugin:

add_filter( 'woocommerce_calc_tax', 'inc_or_exc',10,3 );
// add_filter( 'woocommerce_calculate_totals', 'calculate_totals',11 );
function inc_or_exc( $taxes,$price,$rates ) {
    // echo "<pre>";
    if(!empty(WC()->cart->coupon_discount_amounts)){
        return  WC_Tax::calc_exclusive_tax( $price, $rates );
    }else{
        return  WC_Tax::calc_inclusive_tax( $price, $rates );
    }
}

But it calculates taxes bit strange. If item MRP is 100, it shows 98.85 and also totals are not updating with new taxes and shipping rates after plugin run. If I disable plugin then item MRP is shown fine i.e. 100.

like image 323
عثمان غني Avatar asked Jun 24 '19 13:06

عثمان غني


People also ask

How do you know if a tax is inclusive or exclusive?

Tax Inclusive rates will always include tax in the total that you see in the unit price, whereas Tax Exclusive rates will be excluding the tax that will be added at the point of purchase. Tax exclusive rates will always be lower than the tax inclusive rate, and the difference will increase as the amounts rise.

What is the meaning of exclusive of tax?

Receivables lets you enter and display transaction lines either inclusive or exclusive of tax. Tax inclusive indicates that the line amount for an item includes the tax for this item. Tax exclusive indicates that tax is not included in the line amount for this item.

What is the meaning of inclusive of all taxes?

Inclusive of tax means that the price quoted includes the value of tax. In such cases, a person has to do a back-calculation to arrive at the value of tax.


1 Answers

Finally I have solved it.

First I applied inclusive exlusive filter. Then called woocommerce_calculated_total with custom condition and achieved my motive.

add_filter( 'woocommerce_calc_tax', 'inc_or_exc',10,3 );
// do_action('add_points');

add_filter( 'woocommerce_calculated_total', 'custom_calculated_total', 10, 2 );
function inc_or_exc( $taxes,$price,$rates ) {
    // echo "<pre>";
    if(!empty(WC()->cart->coupon_discount_amounts)){
        return  WC_Tax::calc_exclusive_tax( $price, $rates );
    }else{
        return  WC_Tax::calc_inclusive_tax( $price, $rates );
    }
}

function custom_calculated_total( $total, $cart ){
    // echo "<pre>";
    if(!empty(WC()->cart->coupon_discount_amounts)){
        return round( $total + WC()->cart->get_cart_contents_tax(), $cart->dp );
    }else{
        return round( $total, $cart->dp );
    }   
}
like image 154
عثمان غني Avatar answered Oct 05 '22 20:10

عثمان غني