我为我的所有物品设置了含税价格,并在价格中填写了MRP。但是现在,如果客户未应用优惠券(即在MRP上购买),我想应用含税形式。但是,当客户使用优惠券时,我需要对折后金额应用税。
Woocommerce中的设置是否可能?或者是否有可用的插件?
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
我尝试在自定义插件中使用以下过滤器:
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 );
}
}
但是它计算税款有点奇怪。如果项目MRP为100,则显示98.85,并且在插件运行后,总计不会以新的税费和运费进行更新。如果我停用插件,则MRP项会显示为正常,即100。
答案 0 :(得分:8)
最后我解决了。
首先,我应用了包含性排他性过滤器。然后以自定义条件致电woocommerce_calculated_total
,实现了我的动机。
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 );
}
}