'Conditional filter of Json Data for Javascript booking Calendar

I have a Javascript function that enables dates to be blocked out from a WP Forms (Wordpress Plugin) Calendar. The data is taken from a JSon feed of artists and events.

Currently the function is blocking out dates from all artists in the feed. However, I would like to create a filter to select the date information by the artist - ( "artist" in the Json feed).

So, in effect, I would have a different script for each artist.

The working script is below and the booking form is here - https://www.jonnyrossmusic.com/booking-calendar-test-date-picker/


function wpf_limit_date_picker() {
  
$json = file_get_contents('https://feeds.overturehq.com/feeds/76682d6d/0/208/bookings.json');
$events = json_decode($json, true);
$dates = array();
        
foreach ($events as $event) {
    if (isset($event['date'])) {
             // Assign end date if it exists otherwise set end date as start date
            $end_date = !empty($event['endDate']) ? $event['endDate'] : $event['date'];
              
               // Add date range to date array
             $dates[] = array(
                 "from" => $event['date'],
                     "to" => $end_date,
                );       
        }
}

    ?>
    <script type="text/javascript">
        var d = new Date();
        window.wpforms_70442_4 = window.wpforms_70442_4 || {};
        window.wpforms_70442_4.datepicker = {
            disableMobile: true,
            // Don't allow users to pick specific range of dates
            disable: <?php echo json_encode($dates); ?>
        }
    </script>
    



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source