Hi,
I am sure about where that code to be put. But, with the point you mentioned about when AJAX response is loaded it shows items as per your requirements automatically. So, I am afraid that code that you have might not work too. But, I can check that if you can provide that website link. And also, need to see website for that point which states about YITH infinite loading.
So, let me know link of your website and I am sure I will get solution for this issue.
Let's discuss and I will start working on it right away.