Code-Snippets-Functions/Execute a function on a child site/FacetWP/add-infinity-load-to-load-more-button.txt

24 lines
1,014 B
Text

add_action('wp_footer', 'add_faceet_wp_infinite_scroll');
function add_faceet_wp_infinite_scroll() {
if (is_admin() || is_checkout()) {
return;
}
?>
<script>
jQuery(document).ready(function($){
var intBottomMargin = 1500; //Pixels from bottom when script should trigger
setInterval(() => {
if (($(window).scrollTop() >= $(document).height() - $(window).height() - intBottomMargin)
&& (!$(".facetwp-load-more").hasClass("loading"))
&& (!$(".facetwp-load-more").hasClass("facetwp-hidden"))
) {
$(".facetwp-load-more").addClass('loading');
$(".facetwp-load-more").click(); //trigger click
// the class is automatically removed, as the button is recreated, as soon as it loaded the products
}
}, 1000);
});
</script>
<?php
}