我如何根据客户在 Woocommerce 结账时选择的运输方式收取不同的税率?我的商店有一种运输选项,可以让国际客户避免在泰国这里收取的 7% 增值税。
根据 Woocommerce 文档,以下是在选择“本地取件”作为运输选项时如何禁用税收:
add_filter( 'woocommerce_apply_base_tax_for_local_pickup', '__return_false' );
但我如何禁用自定义运输选项的税收?
编辑:我已经开始制定解决方案,但我可以在第 2 行中使用一些帮助。即如何获取当前的运输方式?
function remove_tax_for_fob( $cart ) {
$ok_remove = get_shipping_method( 'FOB' );
if ($ok_remove){
$cart->remove_taxes();
}
return $cart;
}
add_action( 'woocommerce_calculate_totals', 'remove_tax_for_fob' );
最佳答案
这是解决方案。感谢您的帮助,Anand Shah!
/* Remove tax from cart for FOB orders */
function remove_tax_for_fob( $cart ) {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if($chosen_shipping =='FOB') {
$cart->remove_taxes();
}
return $cart;
}
add_action( 'woocommerce_calculate_totals', 'remove_tax_for_fob' );
关于php - Woocommerce - 根据运输方式计算税收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32902664/