skip to Main Content

How can I hide WooCommerce default content from shop page? So far I have been Googleing like crazy but I cant find any solution.

I found this old answer but this code doesn’t do anything

/**
 * @snippet Remove Product Loop @ WooCommerce Shop
*/
add_action( 'pre_get_posts', 'njengah_remove_products_from_shop_page' );

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

Has anyone got a solution for this issue?

2

Answers


  1. Chosen as BEST ANSWER

    So I accomplished results I wanted with unsetting all the hooks

    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
    remove_action( 'woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10 );
    remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20 );
    remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );
    remove_action( 'woocommerce_archive_description', 'woocommerce_product_archive_description', 10 );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_output_all_notices', 10 );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 );
    remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );
    remove_action( 'woocommerce_before_shop_loop_item', 'woocommerce_template_loop_product_link_open', 10 ); 
    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_show_product_loop_sale_flash', 10 );
    remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 );
    remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 );
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_price', 10 );
    remove_action( 'woocommerce_after_shop_loop_item_title', 'woocommerce_template_loop_rating', 5 );
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_product_link_close', 5 );
    remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
    remove_action( 'woocommerce_after_shop_loop', 'woocommerce_pagination', 10 );
    remove_action( 'woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10 );
    

    Not perfect but It works


  2. add_action('woocommerce_shop_loop', 'reset_woocommerce_shop_loop');
    
    function reset_woocommerce_shop_loop() {
        if (is_shop()) {
            unset($GLOBALS['product']);
            unset($GLOBALS['woocommerce_loop']);
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search