All Wix Stores collections are secured as Private for Admin view only, such collections can only be communicated with via a backend file while suppressing authorization.
The query works in preview because it recognizes your Admin role while working in the editor, not so in the live site.
For the live site you need to query the collection on the backend and return the results to the frontend. Read more about Calling Backend Code From Frontend .
Basically your page code should call the backend function like
// Page Code
import {myServerFnc} from 'backend/stores';
$w.onReady(function () {
myServerFnc()
.then( (res) => {
console.log(res);
});
});
& your backend function should be something like
// Backend Filename: stores.jsw
import wixData from 'wix-data';
let options = {
"suppressAuth": true
};
export function myServerFnc() {
return wixData.query("Stores/Orders")
.find(options)
.then( (results) => {
let orders= results.items
if (orders.length > 0) {
return 'GOT HERE'; // returning value
}
});
}