我的 Woocommerce 商店有 3 种运输方式,当客户选择第 3 种运输方式时,我想禁用税率。
我怎样才能做到这一点?
我的 Woocommerce 商店有 3 种运输方式,当客户选择第 3 种运输方式时,我想禁用税率。
我怎样才能做到这一点?
由于设置似乎无法从特定运输方式中删除税款,请尝试以下代码,将零税设置为您定义的特定运输方式:
add_filter('woocommerce_package_rates', 'null_specific_shipping_method_taxes', 12, 2);
function null_specific_shipping_method_taxes( $rates, $package ){
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return $rates;
// HERE define your targeted shipping methods IDs (in this array)
$shipping_methods_ids = array( 'flat_rate:2', 'flat_rate:12', 'flat_rate:3', 'shipping_by_rules:5' );
// Loop through shipping rates
foreach ( $rates as $rate_key => $rate ){
$has_taxes = false;
// Only for your defined Shipping method IDs
if( in_array( $rate->id, $shipping_methods_ids ) ){
$taxes = [];
// Loop through the shipping taxes array (as they can be many)
foreach ($rates[$rate_key]->taxes as $key => $tax){
if( $rates[$rate_key]->taxes[$key] > 0 ){
// Set each tax cost to zero
$taxes[$key] = 0;
$has_taxes = true;
}
}
// Set the new taxes array
if( $has_taxes )
$rates[$rate_key]->taxes = $taxes;
}
}
return $rates;
}
此代码位于您的活动子主题(或主题)的 function.php 文件中。经过测试并且可以正常工作(如果设置正确,关于 Woocommerce 中的相关运输方式和税金) ……</p>