基于this related answer,如果购物车内装物品总数为零,您可以使用以下选项来隐藏"本地提货"发货选项:
add_filter( 'woocommerce_package_rates', 'hide_local_pickup_for_free_orders', 10, 2 );
function hide_local_pickup_for_free_orders( $rates, $package ) {
// If cart subtotal is equal to zero
if( $package['contents_cost'] == 0 ) {
foreach( $rates as $rate_key => $rate ) {
// Hide Local Pickup shipping method(s)
if ( $rate->method_id === 'local_pickup' ) {
unset($rates[$rate_key]);
}
}
}
return $rates;
}
代码位于您的子主题的unctions.php文件中(或在插件中).经过测试,效果良好.
如果刷新运输方法缓存,则为Important note:,为empty your cart.