Skip to content
← Back to the journal
Tips / Recommendations 1 min read

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' );

Leave a Reply

Your email address will not be published. Required fields are marked *

twenty − 16 =

From insight to action

Need a clear digital solution for your business?

Discuss a project ↗