Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('wc_appointments_find_scheduled_day_slots', function($args, $product) {
- $vendor_id = wcfm_get_vendor_id_by_post($product->get_id());
- if(!$vendor_id) return $args;
- $vendor_data = get_user_meta( $vendor_id, 'wcfmmp_profile_settings', true );
- $vacation_mode = isset( $vendor_data['wcfm_vacation_mode'] ) ? $vendor_data['wcfm_vacation_mode'] : 'no';
- $wcfm_vacation_mode_type = isset( $vendor_data['wcfm_vacation_mode_type'] ) ? $vendor_data['wcfm_vacation_mode_type'] : 'instant';
- $wcfm_vacation_start_date = isset( $vendor_data['wcfm_vacation_start_date'] ) ? $vendor_data['wcfm_vacation_start_date'] : '';
- $wcfm_vacation_end_date = isset( $vendor_data['wcfm_vacation_end_date'] ) ? $vendor_data['wcfm_vacation_end_date'] : '';
- if ( $vacation_mode == 'yes' ) {
- if( $wcfm_vacation_mode_type == 'instant' ) {
- $vacation_arg = array(
- 'type' => 'days',
- 'range' => array(
- '1' => false,
- '2' => false,
- '3' => false,
- '4' => false,
- '5' => false,
- '6' => false,
- '7' => false
- ),
- );
- } elseif( $wcfm_vacation_start_date && $wcfm_vacation_end_date ) {
- $start_time = strtotime( $wcfm_vacation_start_date );
- $end_time = strtotime( $wcfm_vacation_end_date );
- $y = date("Y", $end_time);
- $m = date("m", $end_time);
- $d = date("d", $end_time);
- $range = array();
- while($start_time < $end_time) {
- $year = date("Y", $start_time);
- if(!isset($range[$year])) {
- $range[$year] = array();
- }
- $mon = date("n", $start_time);
- if(!isset($range[$year][$mon])) {
- $range[$year][$mon] = array();
- }
- $date = date("j", $start_time);
- if($y > $year || $m > $mon) {
- $month_days = date("t", $start_time);
- $range[$year][$mon] = array_fill($date, $month_days - $date + 1, false);
- $start_time = strtotime("+1 day", strtotime("{$year}-{$mon}-{$month_days}"));
- } else {
- $range[$year][$mon] = array_fill($date+0, $d - $date + 1, '');
- $start_time = $end_time;
- }
- }
- $vacation_arg = array(
- 'type' => 'custom',
- 'range' => $range,
- );
- }
- if(isset($args['availability_rules'])) {
- $args['availability_rules'][] = array_merge(
- $vacation_arg,
- array(
- 'priority' => 1,
- 'qty' => 0,
- 'level' => 'product',
- 'order' => 0,
- 'kind_id' => $product->get_id(),
- ),
- );
- }
- }
- return $args;
- }, 10, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement