Tagged: woocommerce
-
AuthorPosts
-
January 4, 2015 at 11:25 pm #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' ); }
January 5, 2015 at 6:00 pm #375206Hi 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,
YigitJanuary 6, 2015 at 3:57 pm #375711Have 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?
January 7, 2015 at 6:28 pm #376307Hi!
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!
ElliottJanuary 12, 2015 at 11:29 pm #378570This reply has been marked as private.January 13, 2015 at 12:20 am #378581Ok, 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.
January 13, 2015 at 7:36 pm #379053Hey!
According to this site – http://www.downforeveryoneorjustme.com/ your website is currently down. Please let us know when it is working.
Best regards,
YigitJanuary 14, 2015 at 5:35 pm #379561Sorry, have moved it to production.
http://www.ofas.org.uk/productsJanuary 15, 2015 at 8:46 am #379904Hi!
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!
IsmaelJanuary 19, 2015 at 2:53 pm #381774No, 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.
January 20, 2015 at 9:13 am #382326Hey!
I’m sorry but I may not be understanding you clearly. Can you please provide a screenshot to better explain the issue?
Best regards,
IsmaelJanuary 20, 2015 at 10:21 pm #382750This 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?
January 21, 2015 at 11:25 am #382958Hey!
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!
IsmaelJanuary 21, 2015 at 11:50 pm #383425Amazing – thanks a lot!!!
-
AuthorPosts
- The topic ‘Remove category from Woocommerce’ is closed to new replies.