Tips / Recommendations

Set a cookie and close a popup after Contact Form 7 form is submitted.

<?php
// As is this will check if the form is in a popup, if so set a cookie and close after 5 seconds.

// Copy everything below this line.
function custom_cf7_scripts() { ?>
	<script type="text/javascript">
		var wpcf7Elm = document.querySelector('.wpcf7');

		wpcf7Elm.addEventListener('wpcf7submit', function (event) {
			var $form = $(event.target),
				$popup = $form.parents('.pum');

			if (!$popup.length) {
				return;
			}
			
			$popup.trigger('pumSetCookie');

			setTimeout(function () {
				$popup.popmake('close');
			}, 5000);
		}, false);
	</script><?php
}

add_action( 'wp_footer', 'custom_cf7_scripts' );