Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xlplugins/284e828e116757a9f882ec68b4a257c0 to your computer and use it in GitHub Desktop.
Save xlplugins/284e828e116757a9f882ec68b4a257c0 to your computer and use it in GitHub Desktop.
Funnelkit Cart: Trigger add to cart when page load
class FKCART_Trigger_Add_To_cart_On_Page_Load {
public function __construct() {
add_action( 'wp_footer', [ $this, 'add_js' ] );
}
public function add_js() {
?>
<script>
window.addEventListener('load', function () {
jQuery(document.body).on('fkcart_cart_open', function () {
jQuery('body').trigger('fkcart_update_side_cart', [true]);
});
window.addEventListener('pageshow', function () {
jQuery('body').trigger('fkcart_update_side_cart', [false]);
});
});
</script>
<?php
}
}
new FKCART_Trigger_Add_To_cart_On_Page_Load();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment