Home » WooCommerce: Hide Products @ Shop Page

WooCommerce: Hide Products @ Shop Page

by Tutor Aspire

A client wanted to show only featured products on the shop page. While adding featured products is very easy (just use the WooCommerce shortcode in the page content), it seems very difficult to remove the “default” product loop. Here’s what I did.

WooCommerce Remove Loop at Shop Page
WooCommerce Remove Loop at Shop Page – the old way (commenting out core code). Thankfully there’s a better solution!

PHP Snippet: Hide All Products @ WooCommerce Shop Page

Please note: “Product Catalog” > “Shop page display” must be set to “Show products” in the WordPress > Appearance > Customizer > WooCommerce admin settings. Following snippet won’t work if you only have product categories @ product page.

To hide the “No products were found matching your selection” message that shows once the Shop page has no products to show, use this other snippet.

/**
 * @snippet       Remove Product Loop @ WooCommerce Shop
 * @how-to        Get tutoraspire.com FREE
 * @author        Tutor Aspire
 * @compatible    WooCommerce 6
 * @donate $9     https://www.tutoraspire.com
 */

add_action( 'pre_get_posts', 'tutoraspire_remove_products_from_shop_page' );

function tutoraspire_remove_products_from_shop_page( $q ) {
if ( ! $q->is_main_query() ) return;
if ( ! $q->is_post_type_archive() ) return;
if ( ! is_admin() && is_shop() ) {
$q->set( 'post__in', array(0) );
}
remove_action( 'pre_get_posts', 'tutoraspire_remove_products_from_shop_page' );
}

You may also like