Wednesday, 26 June 2019

Tax exclusive if coupon applied else tax inclusive in items

I am newbie in wordpress development.

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.

Please help.



from Tax exclusive if coupon applied else tax inclusive in items

No comments:

Post a Comment