我需要在周日隐藏 WooCommerce Shipping zone_id=1 和 Shipping zone_id=3。
提出了这段代码:
// Hide $15 & $25 shipping rates on Sunday
add_filter('woocommerce_package_rates', 'amano_hide_shipping_method_on_sunday', 10, 2);
function amano_hide_shipping_method_on_sunday($available_shipping_methods, $package) {
$date = date("1");
$is_sunday = date('l', $date) == 'Sunday';
if($is_sunday) {
$hide_when_shipping_class_exist = array(
42 => array(
'free_shipping'
)
);
$hide_when_shipping_class_not_exist = array(
42 => array(
'wf_shipping_ups:03',
'wf_shipping_ups:02',
'wf_shipping_ups:01'
),
43 => array(
'free_shipping'
)
);
$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]);
}
}
}
foreach($hide_when_shipping_class_not_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;
}
}
然而,我不知道如何定制的是:
$hide_when_shipping_class_exist = array(
42 => array(
'free_shipping'
)
);
$hide_when_shipping_class_not_exist = array(
42 => array(
'wf_shipping_ups:03',
'wf_shipping_ups:02',
'wf_shipping_ups:01'
),
43 => array(
'free_shipping'
)
);
我没有任何运输类别,也不明白它们是什么。可能需要替换更多代码来替换隐藏运输区域的运输类别,但我不知道该代码是什么。
请帮助表示赞赏。
慕妹3242003