本质上,当购物车商品的运输类别为“Roller”(ID )时,我试图flat_rate:7
禁用统一费率方法 Id。92
这是我试过的代码:
add_filter('woocommerce_package_rates', 'wf_hide_shipping_method_based_on_shipping_class', 10, 2);
function wf_hide_shipping_method_based_on_shipping_class($available_shipping_methods, $package)
{
$hide_when_shipping_class_exist = array(
92 => array(
'flat_rate:7'
)
);
$shipping_class_in_cart = array();
foreach(WC()->cart->cart_contents as $key => $values) {
$shipping_class_in_cart[] = $values['data']->get_shipping_class_id();
}
foreach($hide_when_shipping_class_exist as $class_id => $methods) {
if(in_array($class_id, $shipping_class_in_cart)){
foreach($methods as & $current_method) {
unset($available_shipping_methods[$current_method]);
}
}
}
return $available_shipping_methods;
}
运输类别 ID92
是运输类别,我想隐藏flat_rate:7
它。
我的网站是这样的:http: //www.minimoto.me/ WordPress:4.8.4 WooCommerce:3.1.1
任何帮助将不胜感激。