1 回答
TA贡献1824条经验 获得超6个赞
代码包含
在特定的一天
未设置
$rates[$rate_key]
某些区域 ID
注释并添加到代码中的解释
function filter_woocommerce_package_rates( $rates, $package ) {
/* SETTINGS */
// Zone ID's
$hide_zones = array ( 1, 3 );
$on_day = 'Sunday';
/* END SETTINGS */
// Shipping zone
$shipping_zone = wc_get_shipping_zone( $package );
// Get zone ID
$zone_id = $shipping_zone->get_id();
// set the default timezone to use. Available since PHP 5.1
date_default_timezone_set('UTC');
// l - A full textual representation of the day of the week
$day_of_the_week = date( 'l' );
// True
if( $day_of_the_week == $on_day ) {
// In array
if ( in_array( $zone_id, $hide_zones ) ) {
// Loop
foreach ( $rates as $rate_key => $rate ) {
// Unset
unset( $rates[$rate_key] );
}
}
}
return $rates;
}
add_filter( 'woocommerce_package_rates', 'filter_woocommerce_package_rates', 10, 2 );
- 1 回答
- 0 关注
- 120 浏览
添加回答
举报