Viewing 2 replies - 1 through 2 (of 2 total)
  • Ultimate Peter

    (@peastvoldqbservicesnet)

    That would be great! Or, maybe they could make a setting on the category page “Display in shop:On/Off”

    There are some categories of products I only want to display on certain prebuilt pages using WooCommerce shortcodes. I don’t want them to show up on my shop page. I have been looking for how to do this.

    Add this to your function.php replace the category id in the array!

    add_action( ‘pre_get_posts’, ‘custom_pre_get_posts_query’ );
    function custom_pre_get_posts_query( $q )
    {

    if (!$q->is_main_query() || !is_shop()) return;
    if ( ! is_admin() )
    {
    $q->set( ‘tax_query’, array(array(
    ‘taxonomy’ => ‘product_cat’,
    ‘field’ => ‘id’,
    ‘terms’ => array(35, 39 ),
    ‘operator’ => ‘NOT IN’
    )));

    }
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude categories from displaying’ is closed to new replies.