Skip to content

Instantly share code, notes, and snippets.

@danieliser
Created March 30, 2017 07:45
Show Gist options
  • Select an option

  • Save danieliser/9403bcb6081c5902208ce079961ff6b8 to your computer and use it in GitHub Desktop.

Select an option

Save danieliser/9403bcb6081c5902208ce079961ff6b8 to your computer and use it in GitHub Desktop.
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' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment