New Landing How can we help? Themeforest Theme Support Neighborhood Remove Product Category from Shop Page

Viewing 15 posts - 1 through 15 (of 19 total)
  • #78742
    chaismeyer
    Member
    Post count: 9

    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.

    #78769
    chaismeyer
    Member
    Post count: 9

    Nevermind, 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.

    #78774
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Ok great! thanks ๐Ÿ™‚

    – Kyle

    #111493
    bouncingsprouts
    Member
    Post count: 72

    I’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?
    -Dan

    #111501
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    @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
    Mohammad

    #111940
    bouncingsprouts
    Member
    Post count: 72

    I 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,
    Dan

    #112059
    Mohammad – SUPPORT
    Moderator
    Post count: 27441
    This reply has been marked as private.
    #112415
    bouncingsprouts
    Member
    Post count: 72
    This reply has been marked as private.
    #112955
    bouncingsprouts
    Member
    Post count: 72

    Hi any update on this?

    #113114
    bouncingsprouts
    Member
    Post count: 72

    bump

    #113120
    Mohammad – SUPPORT
    Moderator
    Post count: 27441

    Hi,
    I have removed Pack Nappies so please check it now.
    Thanks
    Mohammad

    #218766
    cknetworks
    Member
    Post count: 4

    Hi 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

    #218768
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi @cknetworks,

    Can you provide your site url to that page to see if it’s possible to hide those categories with css?
    thanks

    -Rui

    #218781
    cknetworks
    Member
    Post count: 4
    This reply has been marked as private.
    #218785
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    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

Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register