Created
March 30, 2017 07:45
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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