Any time a user adds an item to their cart on the shop page, the page then scrolls back to the top to display an added to cart message, this is an issue as we have infinite scroll functionality. I want to prevent this, my ideal solution would be to display the message at the top of the screen rather then the top of the page, but as a work around I have tried to implement some JS to bring the customer back down the page to where they were browsing. (however this doesn't work and is not an ideal solution as they wont even see the message).
function cs_wc_loop_add_to_cart_scripts() {
if ( is_shop() || is_product_category() || is_product_tag() || is_product() ) : ?>
<script type="text/javascript">
function refreshPage () {
var page_y = document.getElementsByTagName("body")[0].scrollTop;
window.location.href = window.location.href.split('?')[0] + '?page_y=' + page_y;
}
window.onload = function () {
setTimeout(refreshPage, 35000);
if ( window.location.href.indexOf('page_y') != -1 ) {
var match = window.location.href.split('?')[1].split("&")[0].split("=");
document.getElementsByTagName("body")[0].scrollTop = match[1];
}
}
</script>
<?php endif;
}
add_action( 'wp_footer', 'cs_wc_loop_add_to_cart_scripts' );