• Hi!
    I have two products in two category. I designed the shop page in Visual Editor and put my product’s images. I want to hide the products but keep the page as a shop page. How can I remove all the woocommerce products from the shop page?

    As I have only two categories, I used the below code in my functions.php but not working.

    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( 'cat-slug-1','cat-slug-2' ),
    			'operator' => 'NOT IN'
    		)));
    
    	}
    
    	remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' );
    
    }

    https://www.ads-software.com/plugins/woocommerce/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    If the shop page is not going to display products or categories, why does it need to be kept as the shop page? That doesn’t make much sense – use a regular page.

    Thread Starter Noman Al Sayed

    (@noman393)

    Hi Mike thanks for replying. I need to hide the shop page products because, I have only two products. So, when I am using the woocommerce default product showing the whole page going to be a blank. So I designed a landing page with those products and made the page as a shop page, but in the bottom, the page showing the default products along with my landing page.
    See: https://thrivenowhealth.com/test/shop/
    I am able to remove the the Default shorting Drop-down and Total number of products showing message buy using function.php but need to remove the default products.

    I need the page as a shop page because when someone click to the cart page without adding a product on the cart, the page will show a message like “Return to Shop” and that time I need to show the landing page as a shop page.

    Regards

    Plugin Contributor Mike Jolley

    (@mikejolley)

    You can use a regular page and filter the ‘return to shop’ link to someplace else.

    Or you can create an archive-shop.php template and remove the loop.

    Thread Starter Noman Al Sayed

    (@noman393)

    hey! Thanks Mike. ?? I appreciate your help!

    You can remove specific products, product categories and/or tags from WooCommerce site-wide (which means, from search results, categories page, pages with WooCommerce shortcodes, etc.) by using the WooCommerce Products Visibility plugin.

    You can also choose the user roles to whom the products will be invisible.

    The plugin is also WPML compatible, which means that the rules you define, will take place for all your site’s languages!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to hide any Products from Woocommerce Shop Page?’ is closed to new replies.