I’ve made an action and a function inside functions.php. Then i run the script inside the function, where you call wpcf7.initForm and reload CF7 conditional fields plugin
add_action('wp_ajax_get_event_form', 'get_event_form');
add_action('wp_ajax_nopriv_get_event_form', 'get_event_form');
function get_event_form() {
/* do your php code, query etc. */
?>
<script>
// Init CF7
// because is ajax reload wpcf7.initForm
jQuery('.wpcf7 > form').each(function () {
var $form = jQuery(this);
wpcf7.initForm($form);
if (wpcf7.cached) {
wpcf7.refill($form);
}
});
//load cf7 conditional fields at the end
jQuery.getScript('../../../wp-content/plugins/cf7-conditional-fields/js/scripts.js', function () {
});
</script>
<?php
wp_die();
}