Что то типа этого
function time_range_coupon_id( $coupon_id ) {
// For specific coupon ID's only, several could be added, separated by a comma
// $specific_coupons_ids = array(10700,10700);
// Coupon ID in array, so check
if ($coupon_id=="10700" ) {
// Set the correct time zone (
http://php.net/manual/en/timezones.php)
date_default_timezone_set( 'Asia/Yekaterinburg' );
// Set the start time and the end time to be valid
$start_time = mktime( 11, 00, 00, date( 'm' ), date( 'd' ), date( 'y' ) );
$end_time = mktime( 17, 00, 00, date( 'm' ), date( 'd' ), date( 'y' ) );
$time_now = strtotime( 'now' );
// Return true or false
return $start_time <= $time_now && $end_time >= $time_now ? true : false;
}
// Default
return true;
}
// Is valid
function filter_woocommerce_coupon_is_valid( $is_valid, $coupon, $discount ) {
// Get coupon ID
$coupon_id = $coupon->get_id();
// Call function, return true or false
return time_range_coupon_id( $coupon_id );
}
add_filter( 'woocommerce_coupon_is_valid', 'filter_woocommerce_coupon_is_valid', 10, 3 );