Last active
January 4, 2021 14:07
-
-
Save jamesckemp/c60762ab9db91f9abcfdfb3a484bab66 to your computer and use it in GitHub Desktop.
Change the WooCommerce Delivery Slots by Iconic maximum selectable date dynamically based on time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change maximum delivery date. | |
* https://iconicwp.com/products/woocommerce-delivery-slots/?utm_source=Iconic&utm_medium=Gist&utm_campaign=max-selectable-date | |
* | |
* @param array $max | |
* | |
* @return array | |
*/ | |
function iconic_change_max_delivery_date( $max ) { | |
$current_time = current_time( 'timestamp' ); | |
$ymd = current_time( 'Y-m-d' ); | |
$offset = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; | |
$start = strtotime( $ymd . ' 21:10:00' ) + $offset; | |
$end = strtotime( $ymd . ' 23:59:59' ) + $offset; | |
// If time is not between start and end, return default settings. | |
if ( $current_time < $start || $current_time > $end ) { | |
return $max; | |
} | |
// Add 1 days. (Enables next day delivery). | |
$days_to_add = 1; | |
// This filter returns an array containing the days to add and a timestamp. | |
return array( | |
'days_to_add' => $days_to_add, | |
'timestamp' => strtotime( "+" . $days_to_add . " day", current_time( 'timestamp' ) ), | |
); | |
} | |
add_filter( 'iconic_wds_min_delivery_date', 'iconic_change_max_delivery_date' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment