Last active
October 9, 2022 12:12
-
-
Save ChrisFlannagan/f79ab49491c2b85b0925c66a7fe971fd to your computer and use it in GitHub Desktop.
Woo doesn’t filter out products with hidden catalog visibility outside of main shop loop. This is important to remember when using the REST API for front end display or general search results. This code snippet will keep them from showing outside of the admin. Source: whoischris.com
Hello, Chris - any idea why it will not work on the Category display also? looks like they are still taken in the loop on those
Thanks, saved a lot of time with this function!
By the way I had to make some changes. When tax_query is empty API was throwing me an exception, I had to check whether 'tax_query' was string or array :
if (gettype($tax_query) === 'string') {
$tax_query = [];
}
I have no experience with PHP, maybe it is a better way to fix this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very good, thanks :)
Save my time..
You need to remove public in line 2.
And [] in line 10.