Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Neighborhood › Remove Product Category from Shop Page
New Landing › How can we help? › Themeforest Theme Support › Neighborhood › Remove Product Category from Shop Page
- This topic has 18 replies, 6 voices, and was last updated 9 years by Rui Guerreiro – SUPPORT.
-
Posted in: Neighborhood
-
May 29, 2014 at 3:09 pm #78742
Hey there Swift Ideas Team,
I’m looking to hide/remove specific product categories from specific places on my website and only showing them in other specific pages.
As an example:
I have a product category called “Partners” (ID “274”) and I’d like any product with that category to not be shown (or to load) on my shop pages, but I do want it to show on other specific partner pages.How can I remove this in code because I don’t see a way to disable specific product categories from the shop page in your settings? I’d prefer the code modification to be something I won’t have to change again after an upgrade, maybe making a tweak to the child theme or something.
Thanks so much, looking forward to hearing back.
May 29, 2014 at 4:13 pm #78769Nevermind, I figured it out.
Here’s what I did for others that are interested:
#1) I created a file in my child theme called “functions.php”, adding the following code in the file:
<?php // Leave 3 spaces between these php brackets to put your own custom functions in ?>
#2) Add the following code into that file I just created (and save):
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( 'tax_query', array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'partners' ), // Don't display products in the PARTNERS category on the shop page 'operator' => 'NOT IN' ))); } remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); }
Doing it this way, I’m able to continually add as many custom woocommerce functions (called “Snippets) as I want.
Here are a ton of great customization snippets others might enjoy:
http://docs.woothemes.com/documentation/plugins/woocommerce/woocommerce-codex/snippets/Hope this helps others.
May 29, 2014 at 4:25 pm #78774Ok great! thanks ๐
– Kyle
September 17, 2014 at 5:48 am #111493I’m wanting to hide a category not only on my shop page but also throughout my entire site altogether. I have added the above to my functions.php file and the category is still displayed. I have changed it of course to hide the category on my page rather than ‘partners’. Is there an easier way, perhaps through custom css?
-DanSeptember 17, 2014 at 6:18 am #111501Hi,
@bouncingsprouts- Where did you use this code? Which category do you want to hide? Please attach a marked screenshot and send the website specific page url to explain the issue.
Thanks ๐
With Best Regards
MohammadSeptember 18, 2014 at 3:10 am #111940I was adding the the code in the dashboard to Edit theme > Theme Functions > functions.php
The category I would like to remove from the site is the first category called “Pack Nappies”. http://www.bouncingsprouts.com.au/shop-3
I need the category to exist so I can use it in the nappy packs as a composite product and not affect my other “Nappy” category, when setting up my “Dynamic pricing”.
Thanks,
DanSeptember 18, 2014 at 9:11 am #112059This reply has been marked as private.September 19, 2014 at 6:28 am #112415This reply has been marked as private.September 20, 2014 at 10:12 pm #112955Hi any update on this?
September 22, 2014 at 1:52 am #113114bump
September 22, 2014 at 3:30 am #113120Hi,
I have removed Pack Nappies so please check it now.
Thanks
MohammadOctober 6, 2015 at 11:18 am #218766Hi Mohammad,
I’ve been trying to also completely hide certain product categories from my shop. Is there a way to do this? I’ve entered the code from above, and like bouncingsprouts, the products are no longer displayed, but the category itself is in the sidebar menu.
Please help!
– L
October 6, 2015 at 11:32 am #218768Hi @cknetworks,
Can you provide your site url to that page to see if it’s possible to hide those categories with css?
thanks-Rui
October 6, 2015 at 12:15 pm #218781This reply has been marked as private.October 6, 2015 at 12:27 pm #218785Hi,
There is anything in that widget html that allows us to hide specific categories.
Since there is only 1 category does it really makes sense to have that widget? Just my opinion.Don’t know that plugin, you should test first with the Twenty 15 theme to see if that plugin works.
-Rui
-
Posted in: Neighborhood
You must be logged in and have valid license to reply to this topic.