403]); } // Parse shortcode attributes $atts = $_POST['atts'] ?? []; $page = (int) ($_POST['page'] ?? 1); // Add page to attributes for AJAX pagination $atts['current_page'] = $page; try { $destinationShortcode = new \Yatra\Shortcodes\DestinationShortcode(); $destinations_data = $destinationShortcode->getDestinations($atts); // Prepare data for template - extract variables for template scope $destinations = [ 'destinations' => $destinations_data['destinations'] ?? [], 'max_pages' => $destinations_data['max_pages'] ?? 1, 'current_page' => $destinations_data['current_page'] ?? 1, 'total_found' => $destinations_data['total_found'] ?? 0 ]; // Extract variables to make them available in template $atts = $atts; $max_pages = $destinations_data['max_pages'] ?? 1; $current_page = $destinations_data['current_page'] ?? 1; $total_found = $destinations_data['total_found'] ?? 0; $columns = (int) $atts['columns']; $column_class = 'yatra-destination-grid-' . min(max($columns, 1), 4); // Load the template content with variables in scope ob_start(); // Extract variables to make them available in template (matching trip shortcode pattern) $destinations = $destinations_data['destinations'] ?? []; $max_pages = $destinations_data['max_pages'] ?? 1; $current_page = $destinations_data['current_page'] ?? 1; $total_found = $destinations_data['total_found'] ?? 0; $columns = (int) $atts['columns']; $column_class = 'yatra-destination-grid-' . min(max($columns, 1), 4); include YATRA_PLUGIN_PATH . 'templates/shortcodes/destination.php'; $html = ob_get_clean(); wp_send_json_success([ 'html' => $html, 'current_page' => $destinations_data['current_page'] ?? 1, 'max_pages' => $destinations_data['max_pages'] ?? 1, 'total_found' => $destinations_data['total_found'] ?? 0 ]); } catch (\Exception $e) { wp_send_json_error([ 'message' => (defined('WP_DEBUG') && WP_DEBUG) ? 'Error loading destinations: ' . $e->getMessage() : __('Unable to load destinations. Please try again.', 'yatra'), ]); } } }