Moderator
t-p
(@t-p)
I recommend asking at https://wordpress.org/support/plugin/woocommerce/ so its developers and support community can help you with this.
What code are you using now?
Hi,
I’m currently using the following code to hide member product but for some reason it only hides it but still leaves an empty are on the front page and shop page of where it was.
/**
* Hides membership product from active members
*/
/**
* Hides membership product from active members
*/
function hide_product_from_members( $is_visible, $id ) {
$product_id_to_hide = array(994);
if ( in_array($id, $product_id_to_hide)) {
$is_visible = false;
}
return $is_visible;
}
add_filter( 'woocommerce_product_is_visible', 'hide_product_from_members', 10, 2 );
That filter is only called when a products ‘is_visible()’ function is called, not during any loops or queries so it will never be used in your case.
What would be better is looking at the pre_get_posts filter as that will let you set query conditions as you need to. You need to do a little bit of work to ensure that it’s all correct, but it’s not much.