在WooCommerce中隐藏特定时间的运输方式



我想在特定时间打开一些运输方法,比如

flat_rate:7将只在09.00(24HR(之前显示。我尝试了这个,但不能使用

function conditional_hours_range(){
// HERE below, define start / end hours range and time zone (default is 'UTC').
$start_hour = 17;
$end_hour = 18;
date_default_timezone_set ('Asia/Bangkok');
$now = strtotime("now"); // Now time
$today_time = strtotime(date("Y-m-d")); // Today time at 00:00
$starting_time = $today_time + ( $start_hour * 3600 );
$ending_time = $today_time + ( $end_hour * 3600 );
// return true or false
return $now >= $starting_time && $now <= $ending_time ? false : true;}
add_filter( 'woocommerce_available_payment_gateways', 'hide_payment_gateways_based_on_weight', 11, 1 );
function hide_shipping_gateways_based_on_weight( $available_gateways ) {
if( conditional_hours_range() ){
unset($method_key_id['wbs:1:a78cdfa1_1_09_00']);
// unset 'cod'
}
}

在函数中使用此。php

function remove_shipping_options_for_time($available_shipping_methods, $package) {
global $woocommerce;
if(YOUR_CONDITION){
$available_shipping_methods = array();
}
return $available_shipping_methods;
}

最新更新