Support

Account

Home Forums Front-end Issues Restaurant opening hours with exceptions

Helping

Restaurant opening hours with exceptions

  • Please help me with below code. The code works 99% (only 1 if statement always returns FALSE)

    I have an option page with restaurant opening hours and exceptions. I want to show a OPEN or CLOSED icon (via shortcode) regarding the current opening-status.

    
    // Display opening status as icon
    function yl_opening_status_icon_shortcode() {
    
    	if (have_rows('booking_settings_opening_hours', 'booking_settings')) {
    
    		while (have_rows('booking_settings_opening_hours', 'booking_settings')) { the_row();
    
    			$today_date		= date('Y-m-d'); // DATE OF TODAY
    			$today_day		= date('w'); // WEEKDAY OF TODAY
    			$opening_days	= get_sub_field('booking_settings_opening_hours_day'); // MULTI SELECT FOR OPENING WEEK DAYS
    																				
    		}
    
    	}
    
    	if (have_rows('booking_settings_exceptions', 'booking_settings')) {
    
    		while (have_rows('booking_settings_exceptions', 'booking_settings')) { the_row();
    
    			$exceptions		= get_sub_field('booking_settings_exceptions_date'); // DATE FIELD
    			$exception		= str_replace('/', '-', $exceptions); // BEING SURE ALL DATE FORMATS ARE EQUAL
    			$whole_day		= get_sub_field('booking_settings_exceptions_whole_day'); // YES-NO FIELD
    			$reason			= get_sub_field('booking_settings_exceptions_reason'); // SELECT BOX
    
    			$exception_date	= date("Y-m-d", strtotime($exception)); // GETTING THE EXACT SAME DATE STRING
    
    		}
    
    	}
    
    	if (in_array($today_date, $exception_date)) { // THIS IF STATEMENT ALWAYS RETURNS FALSE, EVEN IF ITS TRUE
    		if ($whole_day) {
    			$output = '	
    				<div>
    					<div class="uk-grid-small uk-flex-middle" uk-grid>
    						<div class="uk-width-1-4@s">
    							<img src="/wp-content/uploads/sites/3/2021/10/Restaurant-Old-Dutch-alert-icon-dicht.svg">
    						</div>
    						<div class="uk-width-expand uk-visible@s">
    							CLOSED
    						</div>
    					</div>
    				</div>
    			';
    
    		} else {
    			$output = '	
    				<div>
    					<div class="uk-grid-small uk-flex-middle" uk-grid>
    						<div class="uk-width-1-4@s">
    							<img src="/wp-content/uploads/sites/3/2021/10/Restaurant-Old-Dutch-alert-icon-open.svg">
    						</div>
    						<div class="uk-width-expand uk-visible@s">
    							OPEN
    						</div>
    					</div>
    				</div>
    			';
    		}
    	} else {
    		if (in_array($today_day, $opening_days)) { // THIS IF STATEMENT WORKS
    			$output = '	
    				<div>
    					<div class="uk-grid-small uk-flex-middle" uk-grid>
    						<div class="uk-width-1-4@s">
    							<img src="/wp-content/uploads/sites/3/2021/10/Restaurant-Old-Dutch-alert-icon-open.svg">
    						</div>
    						<div class="uk-width-expand uk-visible@s">
    							OPEN
    						</div>
    					</div>
    				</div>
    			';
    		} else {
    			$output = '	
    				<div>
    					<div class="uk-grid-small uk-flex-middle" uk-grid>
    						<div class="uk-width-1-4@s">
    							<img src="/wp-content/uploads/sites/3/2021/10/Restaurant-Old-Dutch-alert-icon-dicht.svg">
    						</div>
    						<div class="uk-width-expand uk-visible@s">
    							CLOSED
    						</div>
    					</div>
    				</div>
    			';
    		}
    	}
    
    	return $output;
    
    }
    
    add_shortcode('yl_opening_status_icon','yl_opening_status_icon_shortcode');
    
  • Close this topic…. irrelevant after investigation.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.