简体   繁体   English

如何从商店页面隐藏所有产品和类别(WooCommerce 内容)?

[英]How to hide all products and categories(WooCommerce content) from shop page?

How can I hide WooCommerce default content from shop page?如何从商店页面隐藏 WooCommerce 默认内容? 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?有没有人解决这个问题?

add_action('woocommerce_shop_loop', 'reset_woocommerce_shop_loop');

function reset_woocommerce_shop_loop() {
    if (is_shop()) {
        unset($GLOBALS['product']);
        unset($GLOBALS['woocommerce_loop']);
    }
}

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不完美但有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM