Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alewolf/12f2d9b7ccfc106e94e36e0799ed213b to your computer and use it in GitHub Desktop.
Save alewolf/12f2d9b7ccfc106e94e36e0799ed213b to your computer and use it in GitHub Desktop.
<?php
/**
* If you want to fire the ViewItem event on variable products when
* no variation has been selected yet, then use the following code in
* your functions.php file.
*/
add_action('wp_footer', function () {
?>
<script>
new Promise((resolve) => {
(function waitForjQuery() {
if (window.jQuery) return resolve()
setTimeout(waitForjQuery, 100)
})()
}).then(() => {
jQuery(function () {
jQuery(".single_variation_wrap").on("hide_variation", function () {
jQuery(document).trigger("wpmViewItem")
})
})
})
</script>
<?php
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment