1

I have product category named "Test_category" in my shop. Specifically for that i want to hide this all product from my shop, Only hide for some time not delete or set status as pending from admin.

Regards.

1
2

Add below hook to your theme function.php file

add_action( 'pre_get_posts', 'custom_pre_get_posts' );

function custom_pre_get_posts( $q ) {

    if ( ! $q->is_main_query() ) return;
    if ( ! $q->is_post_type_archive() ) return;

    if ( ! is_admin() && is_shop() ) {

        $q->set( 'tax_query', array(array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array( 'private-clients', 'charity'), // Don't display products in the private-clients category on the shop page
            'operator' => 'NOT IN'
        )));

    }

    remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );

}
5
  • Please explain your answer, how and why it should solve the issue. A code-only answer is a bad one. – Mayeenul Islam Jul 26 '14 at 6:51
  • code is tested one, what is bad can you correct please? – thedarkcoder Jul 30 '14 at 7:51
  • 1
    bad is the less explanation. Just explain how the code is doing what - that'll make the code sense to a non-coder. A copy-paste-work-solved is the worst way of learning - and WPSE is a place for learning. I hope you don't misunderstood me. :) – Mayeenul Islam Jul 31 '14 at 17:06
  • 1
    Ok i got your point. I will take care and explain my solution from now on.. Thanks.. – thedarkcoder Jul 31 '14 at 17:25
  • 1
    The answer seems to originate from docs.woocommerce.com/document/… – DarkNeuron Nov 21 '16 at 13:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.