Why does code work only in preview mode? In a published site code doesn't work (wixsite.com/...)
In most cases the reasons for this problem is one of the following issues:
You forgot to sync the live collection with the sandbox
The collection permissions are set to Admin Only.