Created
July 1, 2025 12:41
-
-
Save xlplugins/284e828e116757a9f882ec68b4a257c0 to your computer and use it in GitHub Desktop.
Funnelkit Cart: Trigger add to cart when page load
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
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