• Tutorials
  • Tips & Tricks
  • Top 10 List
  • WordPress
  • Software
  • Tech
  • Mobile
  • Android
  • Website
  • WooCommerce
  • Games
Anthony Tutorials
  • Tips & Tricks
  • Software
  • Top 10 List
  • WordPress
  • Videos
  • Contact
No Result
View All Result
  • Tips & Tricks
  • Software
  • Top 10 List
  • WordPress
  • Videos
  • Contact
No Result
View All Result
Anthony Tutorials
No Result
View All Result

Hide WooCommerce Product Categories on Shop Page or other Page

Anthony Tutorials by Anthony Tutorials
November 4, 2021
in Tips & Tricks, Tutorials, WooCommerce, Wordpress
Hide WooCommerce Product Categories on Shop Page or other Page web
0
SHARES
118
VIEWS
Share on FacebookShare on TwitterShare on Reddit

You can hide certain WooCommerce product categories from the shop page or other targetted pages, by using an action called wooCommerce_product_query

Add it in your theme via functions.php and it works well…

Or you can easily add this code through plugin called “Code Snippets”.

First of all, you need to activate the plugin called “Code Snippets”.
Then go to the snippets page on the dashboard and click on “add new”. Enter the title you want to call.

Now, Simply add this snippet code mention in below and click “Save changes and activate”.

//<~ dont add me into functions.php 

add_action( 'woocommerce_product_query', 'prefix_custom_pre_get_posts_query' );
/**
 * Hide Product Cateories from targetted pages in WooCommerce
 * @link https://gist.github.com/stuartduff/bd149e81d80291a16d4d3968e68eb9f8#file-wc-exclude-product-category-from-shop-page-php
 *
 */
function prefix_custom_pre_get_posts_query( $q ) {
	
	if( is_shop() || is_page('awards') ) { // set conditions here

	    $tax_query = (array) $q->get( 'tax_query' );
	
	    $tax_query[] = array(
	           'taxonomy' => 'product_cat',
	           'field'    => 'slug',
	           'terms'    => array( 'cat1', 'cat2' ), // set product categories here
	           'operator' => 'NOT IN'
	    );
	
	
	    $q->set( 'tax_query', $tax_query );
	}
}

So the action is wrapped in a conditional statement that targets the pages you want the Product Categories to not display.

Related: How To Display Coupons Used In An Order by email In woocommerce

Related: How To Remove Products On Checkout Page in WooCommerce

 

Well, I hope this article must have helped you. If you have any problem regarding this post just drop your comment here or you can also say “Thanks” simply.

Have fun! 🙂

Tags: Tips & TricksWooCommerceWordpress
Previous Post

WooCommerce Frontend Live Product Editor

Next Post

Adobe Master Collection 2021 Free Download

Related Posts

How to Easily Bulk Delete All WordPress Comments
Tutorials

How to Easily Bulk Delete All WordPress Comments

January 5, 2022
Create A Popup Modal Using Elementor For FREE banner
Tips & Tricks

How To Create A Popup Modal Using Elementor For FREE

December 3, 2021
How to Hide a Recovery Partition Banner
Tech

How to Hide a Recovery Partition (or Any Disk)

December 1, 2021
How to Remove the WooCommerce Quantity Field
Tips & Tricks

How to Remove the WooCommerce Quantity Field

December 1, 2021
Next Post
Adobe Master Collection 2021 Free Download Banner

Adobe Master Collection 2021 Free Download

Like on Facebook

Recent Post

How To Install Windows 8.1 Original ISO File With FREE Product Key 2022
Software

How To Install Windows 8.1 Original ISO File With FREE Product Key 2022

by Anthony Tutorials
May 11, 2022
0

Are you looking for a Windows 8.1 with a free product key? Check our article and learn how to find...

Read more
Adobe Animate 2022 Free Download

Adobe Animate 2022 Free Download

March 26, 2022
How to Easily Bulk Delete All WordPress Comments

How to Easily Bulk Delete All WordPress Comments

January 5, 2022
Adobe Master Collection CC 2022 Free Download

Adobe Master Collection CC 2022 Free Download

December 7, 2021
Create A Popup Modal Using Elementor For FREE banner

How To Create A Popup Modal Using Elementor For FREE

December 3, 2021
Anthony Tutorials

© 2016 - 2022 | Anthonytutorials.com

Navigate Site

  • Contact Us
  • News
  • Video Tutorials

Follow Us

No Result
View All Result
  • Tips & Tricks
  • Software
  • Top 10 List
  • WordPress
  • Videos
  • Contact

© 2016 - 2022 | Anthonytutorials.com

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.