mahfuz118

Directorist - Show only Open Now listings

Nov 22nd, 2021 (edited)
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. add_filter('atbdp_listing_search_query_argument', 'directorist_only_show_open_now_listings');
  2. add_filter('atbdp_all_listings_query_arguments', 'directorist_only_show_open_now_listings');
  3.  
  4. function directorist_only_show_open_now_listings($args)
  5. {
  6.    
  7.     $view = atbdp_get_listings_current_view_name( 'grid' );
  8.     if( $view == 'map' ){
  9.         $args['posts_per_page'] = '-1';
  10.     }
  11.    
  12.     if(is_page(11209)){
  13.  
  14.         $new_args = $args;
  15.         $new_args['posts_per_page'] = '-1';
  16.         $query = new WP_Query($new_args);
  17.         $open = array();
  18.  
  19.         if ($query->have_posts()) {
  20.             while ($query->have_posts()) {
  21.                 $query->the_post();
  22.                 $id = get_the_ID();
  23.                 $business_hours = get_post_meta($id, '_bdbh', true);
  24.                 $always_open = get_post_meta($id, '_enable247hour', true);
  25.                 $no_time = get_post_meta($id, '_disable_bz_hour_listing', true);
  26.                 $business_hours = !empty($business_hours) ? atbdp_sanitize_array($business_hours) : array();
  27.                 if ($no_time) continue;
  28.                 if ($always_open) $open[] = $id;
  29.                 $status = false;
  30.                 $day_ = date('D');
  31.                 $timezone = get_directorist_option('timezone');
  32.                 $timezone = !empty($timezone) ? $timezone : 'America/New_York';
  33.                 $listing_timezone = get_post_meta(get_the_ID(), '_timezone', true);
  34.                 $timezone = !empty($listing_timezone) ? $listing_timezone : $timezone;
  35.                 foreach ($business_hours as $day => $time) {
  36.                    
  37.                     if (empty($time) || empty( $business_hours[$day]['enable'])) continue; // do not print the day if time is not set
  38.                     switch ($day_) {
  39.                         case 'Sat':
  40.                             $status = business_open_close_status($business_hours, $time, 'saturday', $timezone);
  41.                             break;
  42.                         case 'Sun':
  43.                             $status = business_open_close_status($business_hours, $time, 'sunday', $timezone);
  44.                             break;
  45.                         case 'Mon':
  46.                             $status = business_open_close_status($business_hours, $time, 'monday', $timezone);
  47.                             break;
  48.                         case 'Tue':
  49.                             $status = business_open_close_status($business_hours, $time, 'tuesday', $timezone);
  50.                             break;
  51.                         case 'Wed':
  52.                             $status = business_open_close_status($business_hours, $time, 'wednesday', $timezone);
  53.                             break;
  54.                         case 'Thu':
  55.                             $status = business_open_close_status($business_hours, $time, 'thursday', $timezone);
  56.                             break;
  57.                         case 'Fri':
  58.                             $status = business_open_close_status($business_hours, $time, 'friday', $timezone);
  59.                             break;
  60.                     }
  61.                 }
  62.  
  63.                 if ($status) {
  64.                     $open[] = get_the_ID();
  65.                 }
  66.                        
  67.             }
  68.         }
  69.  
  70.  
  71.         wp_reset_postdata();
  72.  
  73.         if (count($open) > 0) {
  74.             $args['post__in'] = $open;
  75.         }
  76.     }
  77.  
  78.     return $args;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment