Skip to content

Instantly share code, notes, and snippets.

@btribouillet
Created September 14, 2018 13:33
Show Gist options
  • Save btribouillet/d6d053ba95434c926451f92b6a51e39e to your computer and use it in GitHub Desktop.
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
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 );
/**
* 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;
}
@alasdairmacewan
Copy link

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