Title: Woocommerce Exclude Hidden Products PHP Function
Last modified: November 17, 2021

---

# Woocommerce Exclude Hidden Products PHP Function

 *  [paul13234](https://wordpress.org/support/users/pavelreuk/)
 * (@pavelreuk)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-exclude-hidden-products-php-function/)
 * Hi,
 * Does anyone have a snippet I can add to exclude hidden products from the home
   page and shop page?
 * Thanks.
    -  This topic was modified 4 years, 5 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Everything else WordPress
      topic

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Moderator [t-p](https://wordpress.org/support/users/t-p/)
 * (@t-p)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-exclude-hidden-products-php-function/#post-15075617)
 * I recommend asking at [https://wordpress.org/support/plugin/woocommerce/](https://wordpress.org/support/plugin/woocommerce/)
   so its developers and support community can help you with this.
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-exclude-hidden-products-php-function/#post-15075637)
 * What code are you using now?
 *  Thread Starter [paul13234](https://wordpress.org/support/users/pavelreuk/)
 * (@pavelreuk)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-exclude-hidden-products-php-function/#post-15075662)
 * 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 );
       ```
   
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-exclude-hidden-products-php-function/#post-15075712)
 * 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](https://developer.wordpress.org/reference/hooks/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.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Woocommerce Exclude Hidden Products PHP Function’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 3 participants
 * Last reply from: [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/woocommerce-exclude-hidden-products-php-function/#post-15075712)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
