• 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. 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

    (@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?

    Thread Starter paul13234

    (@pavelreuk)

    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.

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

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