{"id":54984,"date":"2020-01-24T16:28:59","date_gmt":"2020-01-24T15:28:59","guid":{"rendered":"https:\/\/samuelchopard.ch\/wiki\/?p=54984"},"modified":"2020-01-24T17:53:23","modified_gmt":"2020-01-24T16:53:23","slug":"exclude-products-from-a-particular-category-on-the-shop-page","status":"publish","type":"post","link":"https:\/\/samuelchopard.ch\/wiki\/library\/exclude-products-from-a-particular-category-on-the-shop-page\/","title":{"rendered":"Exclude products from a particular category on the shop page"},"content":{"rendered":"<p><!--more--><br \/>\nAdd the following code in functions.php:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">\/* Exclude products in the promo category on the shop page *\/\r\nfunction custom_pre_get_posts_query( $q ) {\r\n    $tax_query = (array) $q-&gt;get( 'tax_query' );\r\n    $tax_query[] = array(\r\n           'taxonomy' =&gt; 'product_cat',\r\n           'field' =&gt; 'slug',\r\n           'terms' =&gt; array( 'clothing' ), \/\/ Don't display products in the clothing category on the shop page.\r\n           'operator' =&gt; 'NOT IN'\r\n    );\r\n    $q-&gt;set( 'tax_query', $tax_query );\r\n}\r\nadd_action( 'woocommerce_product_query', 'custom_pre_get_posts_query' );<\/pre>\n<p>Edit name of category as needed.<\/p>\n<p><strong>Important:<\/strong><br \/>\nProducts will also be hidden in search. If you want to display the products in search, the easiest solution is to set the products &#8220;catalogue visibility&#8221; to &#8220;search results only&#8221; and use a shortcode to display the products on another page. The shortcode must contain &#8220;visibility=search&#8221;. Here is an example of shortcode: <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">[products category=category_name columns=3 visibility=search]<\/pre>\n<p>Source: <a target=\"_blank\" href=\"https:\/\/docs.woocommerce.com\/document\/exclude-a-category-from-the-shop-page\/\">https:\/\/docs.woocommerce.com\/document\/exclude-a-category-from-the-shop-page\/<\/a>, <a target=\"_blank\" href=\"https:\/\/docs.woocommerce.com\/document\/woocommerce-shortcodes\/\">https:\/\/docs.woocommerce.com\/document\/woocommerce-shortcodes\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"Add the following code in functions.php: \/* Exclude products in the promo category on the shop page *\/ function custom_pre_get_posts_query( [...]","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-54984","post","type-post","status-publish","format-standard","hentry","category-woocommerce"],"_links":{"self":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/comments?post=54984"}],"version-history":[{"count":9,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54984\/revisions"}],"predecessor-version":[{"id":54993,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/posts\/54984\/revisions\/54993"}],"wp:attachment":[{"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/media?parent=54984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/categories?post=54984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/samuelchopard.ch\/wiki\/wp-json\/wp\/v2\/tags?post=54984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}