Reputation: 101
I am using the following code to hide the product loop on the Woo shop page:
add_action( 'pre_get_posts', 'bbloomer_remove_products_from_shop_page' );
function bbloomer_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( 'tax_query', array(array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => array( 'null' ),
'operator' => 'IN'
)));
}
remove_action( 'pre_get_posts', 'bbloomer_remove_products_from_shop_page' );
}
function wc_no_products_found() {
if ( is_shop() ) {
echo '<style>p.woocommerce-info{display:none}</style';
}
}
It works. It removes all the products and the Woo no products found error message.
The problem is as follows:
Because the above code removes the no products found error message. In the event that someone searches one of my categories for something that does not exist, the resulting search result page is blank also.
So in simple terms, I want to remove the no products found error message only from the shop page. Where I have removed all products. And still have the error message show up on a (unsuccessful) search result page.
Thanks in advance for any help.
Upvotes: 2
Views: 3629
Reputation: 31
If archive-product.php
doesn't change anything add:
add_theme_support('woocommerce');
to your functions.php
Upvotes: 1
Reputation: 494
add_action( 'woocommerce_no_products_found', function(){
if(is_shop()) {
remove_action( 'woocommerce_no_products_found', 'wc_no_products_found', 10 );
}
}, 9 );
I hope this code help you
Upvotes: 4