Home Forums WoodMart support forum Hide certain products from main product archiv

Hide certain products from main product archiv

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #565352

    x7media.de
    Participant

    Hi,
    how can I hide certain products from the product archive. These are optional products that can be ordered in addition to a main product.

    I have created these under the “Options” category and would like to hide them.

    Best regards
    Norbert

    #565502

    Hello,

    Please add below code to functions.php file in Child theme:

    // WooCommerce – Exclude Products from Shop Page using IDs.
    // =============================================================================

    add_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    function custom_pre_get_posts_query( $q ) {
    
      if ( ! $q->is_main_query() ) return;
      if ( ! $q->is_post_type_archive() ) return;
      
      if ( ! is_admin() && is_shop() ) {
    
        $q->set( 'post__not_in', array(1216, 1185) ); // Replace 70 and 53 with your products IDs. Separate each ID with a comma.
      
      }
      remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    }

    Best Regards.

Viewing 2 posts - 1 through 2 (of 2 total)