Created
September 14, 2018 13:33
-
-
Save btribouillet/d6d053ba95434c926451f92b6a51e39e to your computer and use it in GitHub Desktop.
Feature request (WooCommerce Delivery Slots): Add a filter in slots_available_on_date function
This file contains 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
function domain_set_slot_availability( $is_available, $timeslot, $date ) { | |
// Custom code to set $is_available to false or true. | |
return $is_available; | |
} | |
add_filter( 'iconic_wds_slot_available', 'domain_set_slot_availability', 10, 3 ); |
This file contains 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
/** | |
* Helper: Get all slots available on a specific date | |
* | |
* @param string $date Ymd | |
* | |
* @return array | |
*/ | |
function slots_available_on_date( $date ) { | |
$timeslots = $this->get_timeslot_data(); | |
$datetime = DateTime::createFromFormat( 'Ymd', $date ); | |
$date_timestamp = $datetime->getTimestamp(); | |
$available_timeslots = array(); | |
if ( ! $timeslots ) { | |
return $available_timeslots; | |
} | |
foreach ( $timeslots as $timeslot ) { | |
$slot_id = sprintf( '%s_%s', $date, $timeslot['id'] ); | |
$slot_allowed_on_day = $this->is_timeslot_available_on_day( $date_timestamp, $timeslot ); | |
$in_past = $this->is_timeslot_in_past( $timeslot, $date ); | |
$slot_allowed_for_method = $this->is_timeslot_allowed_for_method( $timeslot ); | |
/* START : apply_filters added */ | |
$slot_allowed_filter = apply_filters( 'iconic_wds_slot_available', true, $timeslot, $date ); | |
if ( ! $slot_allowed_on_day || $in_past || ! $slot_allowed_for_method || ! $slot_allowed_filter ) { | |
continue; | |
} | |
/* END: apply_filters added */ | |
$slots_available_count = $this->get_slots_available_count( $timeslot, $date ); | |
if ( $slots_available_count <= 0 ) { | |
continue; | |
} | |
$timeslot['slot_id'] = $slot_id; | |
$available_timeslots[] = $timeslot; | |
} | |
return $available_timeslots; | |
} |
Hi, yes it certainly does help, however Im terrible at PHP,
Can you help me with this a little,
I know it in english what I want it to do but just not how to write it in PHP
So basically I want it to be something like this
If shipping method Xmas is selected then show 22 december 23rd december and 24th december and then it should also allow for the time slots to work within this if statement
I think that makes sense on how to approach this problem
Many thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @alasdairmacewan,
This was a feature request for the plugin Iconic delivery slot. They did add the hook / filter but with a different name. iconic_wds_is_timeslot_available_on_day
So the way I'm using it now is like that.
But this will only disable each or a specific timeslot for the selected date.
If you want you can also use iconic_wds_slots_available_on_date hook or iconic_wds_is_day_allowed hook.
I see there is also a hook called iconic_wds_timeslot_shipping_method_allowed. It might worth to look into that.
Let me know if that helps.