Problem with ACF Date Range and Repeater Integration in WooCommerce

I am using ACF to create fields integrated with WooCommerce. I am struggling to manage the tour status for each period in the Week Days mode:

The tour has 2 modes: Week Days and Exact Dates.
A tour can have multiple periods (using the repeater field tour_period).
When selecting Week Days mode, the tour_period contains field groups tour_date_range, which include tour_start_date and tour_end_date. When selecting Exact Dates, the range is not used but replaced with tour_dates (which is a repeater field and can be added as many times as needed).
Each period has a field tour_booked (checkbox, false/true).
I want to display a message when the tour is marked as booked (using an AJAX call for live checking).
The status of tour_booked for one period should not affect other periods (in cases where one tour has multiple periods).
The current issue in Week Days mode is that when one period has tour_booked set to true, other periods also display the same message, preventing all periods from being booked.

This problem does not occur in Exact Dates mode.

I have tried many approaches but still have issues in Week Days mode.

Here is my code:

  1. Handler

if (!class_exists('My_Tour_Fields_Handler')) {

    class My_Tour_Fields_Handler {
        const DATE_FORMAT = 'Y-m-d';

        public static function get_date_format() {
            return self::DATE_FORMAT;
        }

        public static function get_tour_mode($product_id) {
            return get_field('tour_mode', $product_id);
        }

        public static function get_tour_period($product_id) {
            return get_field('tour_period', $product_id);
        }

        public static function is_tour_booked($product_id, $selected_date) {
            $tour_period = self::get_tour_period($product_id);
            $tour_booked = false;

            if ($tour_period) {
                $tour_mode = strtolower(trim(self::get_tour_mode($product_id)));
                
                foreach ($tour_period as $period) {
                    if ($tour_mode === 'exact dates' && isset($period['exact_dates']) && is_array($period['exact_dates'])) {
                        foreach ($period['exact_dates'] as $date) {
                            if (isset($date['exact_date']) && $date['exact_date'] === $selected_date && isset($period['tour_booked']) && $period['tour_booked'] === true) {
                                $tour_booked = true;
                                break 2;
                            }
                        }
                    } elseif ($tour_mode === 'week days' && isset($period['tour_date_range'])) {
                        $tour_date_range = $period['tour_date_range'];
                        if (isset($tour_date_range['tour_start_date']) && isset($tour_date_range['tour_end_date'])) {
                            $start_date = $tour_date_range['tour_start_date'];
                            $end_date = $tour_date_range['tour_end_date'];
                            // Convert dates to timestamp for comparison
                            $selected_date_ts = strtotime($selected_date);
                            $start_date_ts = strtotime($start_date);
                            $end_date_ts = strtotime($end_date);
                            
                            if ($selected_date_ts >= $start_date_ts && $selected_date_ts <= $end_date_ts && isset($period['tour_booked']) && $period['tour_booked'] === true) {
                                $tour_booked = true;
                                break;
                            }
                        }
                    }
                }
            }

            return $tour_booked;
        }

        public static function generate_hidden_product_id_input($product_id) {
            // Ensure that the product ID is valid
            if (!is_numeric($product_id)) {
                return '';
            }

            // Return HTML for hidden input field
            return '<input type="hidden" id="product_id" name="product_id" value="' . esc_attr($product_id) . '">';
        }
    }
}
?>
  1. Checker
include_once MY_TOUR_PLUGIN_DIR . 'includes/config/config-tour-date.php';
include_once MY_TOUR_PLUGIN_DIR . 'includes/class-tour-fields-handler.php'; 

// Enqueue JS and insert inline script
function my_enqueue_tour_booked_scripts() {
    wp_enqueue_script('jquery');
    wp_add_inline_script('jquery', '
    jQuery(document).ready(function ($) {
        const dateSelector = `#' . TOUR_DATE_SELECTOR_ID . '`;

        $(dateSelector).on("change", function () {
            const selectedDate = $(this).val();
            const productId = $("input[name='product_id']").val();

            if (selectedDate && productId) {
                $.ajax({
                    url: "' . admin_url('admin-ajax.php') . '",
                    type: "POST",
                    data: {
                        action: "check_tour_booked",
                        product_id: productId,
                        selected_date: selectedDate
                    },
                    success: function (response) {
                        if (response.success) {
                            alert(response.data.message);
                        } else {
                            alert("Error: " + response.data.message);
                        }
                    },
                    error: function () {
                        alert("AJAX error.");
                    }
                });
            }
        });
    });
    ');
}
add_action('wp_enqueue_scripts', 'my_enqueue_tour_booked_scripts');

// Insert hidden input for product_id on single product page
function my_add_hidden_product_id() {
    global $product;
    if (is_product() && $product) {
        echo '<input type="hidden" name="product_id" value="' . $product->get_id() . '">';
    }
}
add_action('woocommerce_before_add_to_cart_button', 'my_add_hidden_product_id');

// AJAX handler to check if the tour is fully booked
function my_check_tour_booked() {
    if (isset($_POST['product_id']) && isset($_POST['selected_date'])) {
        $product_id = sanitize_text_field($_POST['product_id']);
        $selected_date = sanitize_text_field($_POST['selected_date']);

        $is_booked = My_Tour_Fields_Handler::is_tour_booked($product_id, $selected_date);

        if ($is_booked) {
            wp_send_json_success(array('message' => 'Tour is fully booked.'));
        } else {
            wp_send_json_success(array('message' => 'Date available.'));
        }
    } else {
        wp_send_json_error(array('message' => 'Invalid data.'));
    }
}
add_action('wp_ajax_check_tour_booked', 'my_check_tour_booked');
add_action('wp_ajax_nopriv_check_tour_booked', 'my_check_tour_booked');
?>

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật