Home » WordPress » How do we remove shop loop from woocommerce store page? – PHP code

How do we remove shop loop from woocommerce store page? – PHP code

if you want to hide/remove the product listing in your woocommerce home page ( store front) you can use bellow function and filter.

PHP code goes to function.php

here using this action we are targetting the shop page  add_action( ‘pre_get_posts’, ‘remove_products_from_shop_page’ ); 

and php function checking some codition and adding of loops and remove action

// remove shop loop form woocommerce home page
add_action( 'pre_get_posts', 'remove_products_from_shop_page' );

function 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', 'remove_products_from_shop_page' );
}

this will be the out put

To remove the “No products where found matching your selection” notification you can use bellow php code or simply you can hide this message using CSS ( target the home body class and hide the element using css )

remove_action( 'woocommerce_no_products_found', 'wc_no_products_found' );

if this code snippet not work?, please let me know in the comments . I would be happy to revise the code if you report. this code snippet tested on latest wooCommerce version 8.1.1

Duminda Wijerathna

An all round web designer building websites Over 18 years. Interested in achieving a suitable placement in the field of IT in a growth oriented organization which offers diverse job responsibilities in order to utilize and improve my skills, Knowledge and experience.

Leave a Comment

Your email address will not be published. Required fields are marked *