How to display calendar colors based on number of reservations
-
Hello there! I’ve created a custom snippet to display the calendar colors based on the number of reservation made by people. I’ve checked and the code works perfectly if I force the publication through the plug in settings. Basically, it creates the record and makes the count of all the total reservation, however, unless I press “publish” it would not show the actual color in front end. Could you please have a look and advise? Here’s the code I am using:
include '/wp-content/plugins/availability-calendar/admin/includes/owac-functions.php'; $servername = '***'; $username = '***'; $password = '***'; try { $conn = new PDO("mysql:host=localhost;dbname=***", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully <br>"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $months = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'); $date = date('Y-m'); $days = date('t'); $counter_pallini_in_calendario = 0; $reservation = (int) $results['reservation']; for($i = 4; $i <= $days; $i++){ if($i < 10 ){ $g = '0'.$i; } else { $g = $i; } $giorni = $date.'-' . $g; $date_day = new DateTime($giorni); //echo $date_day->getTimestamp(); $reservation_seats_per_day = $conn->query("SELECT COUNT(*) AS reservation FROM gSo9L5Vt_postmeta WHERE meta_key = 'wbtm_journey_date' AND meta_value = '".$giorni."'"); $results_query = $reservation_seats_per_day->fetch(); $reservation_this = (int) $results_query['reservation']; echo "<br> Numero posti prenotati per il giorno : ".$giorni. " è : ".$reservation_this; $total_seats = 252; $seat_availability_percentage = ($reservation_this / $total_seats) * 100; echo "<br>".$seat_availability_percentage . "%" . "<br>"; //query tabella calendario : recupero from_date dalla tabella; se presente QUERY UPDATE AGGIORNANDO cat_id = 2 SE seat_availability_percentage > 40% ; ALTRIMENTI INSERT cat_id = 1; $check = $conn->query("SELECT COUNT(*) AS c FROM
gSo9L5Vt_OWAC_event
WHERE from_date = '" .$date_day->getTimestamp()."' "); $q = $check->fetch(); $counter_pallini_in_calendario = (int) $q['c']; if($counter_pallini_in_calendario == 0) { //INSERT IN DB $insert_pallini = $conn->prepare("INSERT INTO gSo9L5Vt_OWAC_event (from_date, to_date, cat_id, created_date, status, flag) VALUES (:timesta, :timesta, 1, :timesta, 1, 0) "); $insert_pallini->bindValue(':timesta', $date_day->getTimestamp(), PDO::PARAM_STR); $insert_pallini->execute(); } else { if($seat_availability_percentage >= 25 && $seat_availability_percentage <50){ $color = 3; } else if ($seat_availability_percentage >= 50 && $seat_availability_percentage <80){ $color = 4; } else if ($seat_availability_percentage >= 80 && $seat_availability_percentage <99){ $color = 5; } else if ($seat_availability_percentage >= 99){ $color = 2; } $update_pallini = $conn->query("UPDATE gSo9L5Vt_OWAC_event SET cat_id = '".$color."' WHERE from_date = '".$date_day->getTimestamp()."' "); $update_pallini->execute();The page I need help with: [log in to see the link]
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to display calendar colors based on number of reservations’ is closed to new replies.