Tagged: 

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #374814

    Firstly, awesome theme – really, really great.

    There are three things I am trying to do but I’ll split them into 3 posts so they can be found more easily if they are solved.

    I found a post with the following code to hide a category from the shop page, but it doesn’t seem to work when put in my child theme functions.php, any ideas?

    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( 'knives' ), // Don't display products in the knives category on the shop page
    			'operator' => 'NOT IN'
    		)));
    	
    	}
    
    	remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }
    #375206

    Hi alanboyle5355!

    In the example code, “knives” category should be hidden on the shop page. Please make sure that you inserted your category name instead of “knives”. You can easily choose which categories you would like to display using ALB elements such as Product Grid – http://i.imgur.com/gAsEnEX.png

    Best regards,
    Yigit

    #375711

    Have added the code and changed “knives” to “featured” but no luck as you can see here: http://ofas.org.uk.gridhosted.co.uk/products/

    Does the Product Grid have filters and search?

    #376307

    Hi!

    I tested your code on my XAMPP setup and it’s working fine. It’s only going to work on actual products in your shop page though.

    I viewed your link but I’m not sure what shortcode your using there. Send us a WordPress login and we’ll take a look.

    Cheers!
    Elliott

    #378570
    This reply has been marked as private.
    #378581

    Ok, so quick update. The code does work, but I didn’t realise that it removes the products themselves from the store!

    What I’m trying to do is hide just the category from the list of categories that appears when you go to the main store page.

    #379053

    Hey!

    According to this site – http://www.downforeveryoneorjustme.com/ your website is currently down. Please let us know when it is working.

    Best regards,
    Yigit

    #379561

    Sorry, have moved it to production.
    http://www.ofas.org.uk/products

    #379904

    Hi!

    Are you trying to remove the categories from the Woocommerce Product Categories widget? Please use this on functions.php:

    //* Used when the widget is displayed as a dropdown
    add_filter( 'woocommerce_product_categories_widget_dropdown_args', 'rv_exclude_wc_widget_categories' );
    //* Used when the widget is displayed as a list
    add_filter( 'woocommerce_product_categories_widget_args', 'rv_exclude_wc_widget_categories' );
    function rv_exclude_wc_widget_categories( $cat_args ) {
    	$cat_args['exclude'] = array('24','26'); // Insert the product category IDs you wish to exclude
    	return $cat_args;
    }

    Cheers!
    Ismael

    #381774

    No, the main catalogue page is set to display the categories rather than individual products. I have a category called Featured to use on the front page Product Grid, but that means that on my catalogue page there is a link to the Featured category which I don’t want.

    #382326

    Hey!

    I’m sorry but I may not be understanding you clearly. Can you please provide a screenshot to better explain the issue?

    Best regards,
    Ismael

    #382750

    This is the “Products” page. How do I stop it showing the category “Featured” in the red box, but still have those products showing inside the other categories they are in?

    #382958

    Hey!

    We added this on the child theme’s functions.php:

    /**
     * 
     * Remove featured image from Products page.
     */
    add_filter( 'get_terms', 'get_subcategory_terms', 10, 3 );
    function get_subcategory_terms( $terms, $taxonomies, $args ) {
     
      $new_terms = array();
     
      // if a product category and on the shop page
      if ( in_array( 'product_cat', $taxonomies ) && ! is_admin() && is_shop() ) {
     
        foreach ( $terms as $key => $term ) {
     
          if ( ! in_array( $term->slug, array( 'featured' ) ) ) {
            $new_terms[] = $term;
          }
     
        }
     
        $terms = $new_terms;
      }
     
      return $terms;
    }

    Cheers!
    Ismael

    #383425

    Amazing – thanks a lot!!!

Viewing 14 posts - 1 through 14 (of 14 total)
  • The topic ‘Remove category from Woocommerce’ is closed to new replies.