1 回答
![?](http://img1.sycdn.imooc.com/54585050000156a302200220-100-100.jpg)
TA贡献1998条经验 获得超6个赞
要将其用于所有“统一费率”送货方式和某些其他定义的送货方式,请改用以下内容:
add_filter( 'woocommerce_package_rates', 'hide_shipping_method_based_on_shipping_class', 10, 2 );
function hide_shipping_method_based_on_shipping_class( $rates, $package )
{
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
// HERE define your shipping class to find
$class = 92;
// HERE define the shipping methods you want to hide (others than "flat rate")
$method_key_ids = array('local_pickup:3');
$found = false;
// Checking in cart items
foreach( $package['contents'] as $cart_item ){
// If we find the shipping class
if( $cart_item['data']->get_shipping_class_id() == $class ){
$found = true;
break; // Stop the loop
}
}
if( ! $found )
return $rates;
// Loop through shipping methods
foreach( $rates as $rate_key => $rate ) {
// Targetting "Flat rate" and other defined shipping mehods
if( 'flat_rate' === $rate->method_id || in_array($rate->id, $method_key_ids) ) {
unset($rates[$rate_key]);
}
}
return $rates;
}
代码进入您的活动子主题(或活动主题)的function.php文件中。经过测试和工作。
刷新运输缓存:( 必填)
该代码已保存在活动主题的function.php文件中。
购物车是空的
在运送区域设置中,禁用/保存任何运送方法,然后启用返回/保存。
- 1 回答
- 0 关注
- 209 浏览
添加回答
举报