As sometimes recommended here I am using “the grid” to display a grid of products from a Woocommerce shop.
I have set some products to be visibility=hidden in the Woocommerce catalog/search, but this has no effect on the result displayed in my grid.
Seems Woocommerce used to use a meta key for visibility but has since changed to using a taxonomy value.
Does anyone know how best to filter my grid accordingly? At the moment I am having to do a manual exclude by post ID.
Hello Steve,
Thanks for writing in!
Normally when the products use the custom fields to show or hide the product in the catalog search, you use Meta Filtering in TheGrid plugin.
Now, as you have said that Woocommerce is using the taxonomy, you will use the category filter instead.
If this is not helping, kindly provide us access to your site so that we can check your settings. Please create a secure note with the following info:
– Link to your site
– WordPress Admin username / password
To know how to create a secure note, please check this out: https://theme.co/docs/getting-support
Regards.
Thank you @ruenel ! I agree with you that would be the most obvious and best way to do it, by setting a category filter, but when I try to do that I am only given the choice of my existing product categories and/or tags. The taxonomy for Woocommerce product visibility is not included:
I think this is something that can only be fixed by “the grid” plugin author - what do you think?
A workaround would be to create a special category or tag called “hidden” for example and use that to filter by. But the drawback there would by that I do not want a category or tag button or text showing up on my site that says “hidden”.
Well. After a bit of Google searching I came up with some code which I added to my child theme which seems to fix it. I thought I would share it here in case it can help anyone else:
// Modify "The Grid" plugin so that it doesn't show Woocommerce posts which have visibility set to "hidden"
// =============================================================================
function the_grid_query_arguments($query_args, $grid_name) {
if ($grid_name == 'My grid name') {
$query_args['tax_query'][] = array(
'tax_query' => array(
array(
'taxonomy' => 'product_visibility',
'field' => 'slug',
'terms' => array('exclude-from-search', 'exclude-from-catalog'),
'operator' => 'NOT IN',
),
),
);
}
return $query_args;
}
add_filter('tg_wp_query_args', 'the_grid_query_arguments', 10, 2);
Hello Steve,
We are just glad that you have figured it out a way to correct the said issue.
Thanks for letting us know!
Best Regards.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.